Skip to content

Commit

Permalink
fix(ios): event sessioncompleted does not get all specified values (#…
Browse files Browse the repository at this point in the history
…11782)

Fixes TIMOB-27821
  • Loading branch information
vijaysingh-axway authored Jul 6, 2020
1 parent c2e5fb5 commit ebae7bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
15 changes: 11 additions & 4 deletions apidoc/Titanium/App/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ events:
Fired to indicate that a [urlSession](Modules.URLSession) task finished transferring data.
Available only on iOS 7 and later.
description: |
This event only needs to be used if your app is using the `urlSession` module to download data.
This event only needs to be used if your app is using the `urlSession` module to download or upload data.
Server errors are not reported through the error parameter. The only error events sent
through the error parameter are client-side errors, such as being unable to resolve
Expand All @@ -1251,16 +1251,23 @@ events:
type: Number

- name: message
summary: A string containing the localized description of the error.
summary: |
A string containing the localized description of the error.
This property does not exhist if errorCode is 0, which means there is no error.
type: String

- name: responseText
summary: The response text for upload tasks (since SDK 7.2.0).
summary: |
The response text for [task](Modules.URLSession.task) and [uploadTask](Modules.URLSession.uploadTask).
This property does not exhist for download task. For download task response,
use [downloadcompleted](Titanium.App.iOS.downloadcompleted) event.
type: String
since: "7.2.0"

- name: statusCode
summary: The response status code for upload tasks (since SDK 7.2.0).
summary: The response status code for tasks.
type: Number
since: "7.2.0"
osver: {ios: {min: "7.0"}}
since: "3.2.0"

Expand Down
19 changes: 10 additions & 9 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,7 @@ - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)data
NSMutableDictionary *responseObj = [uploadTaskResponses objectForKey:@(dataTask.taskIdentifier)];
if (!responseObj) {
NSMutableData *responseData = [NSMutableData dataWithData:data];
NSInteger statusCode = [(NSHTTPURLResponse *)[dataTask response] statusCode];
responseObj = [NSMutableDictionary dictionaryWithObjectsAndKeys:@(statusCode), @"statusCode", responseData, @"responseData", nil];
responseObj = [NSMutableDictionary dictionaryWithObjectsAndKeys:responseData, @"responseData", nil];
[uploadTaskResponses setValue:responseObj forKey:(NSString *)@(dataTask.taskIdentifier)];
} else {
[[responseObj objectForKey:@"responseData"] appendData:data];
Expand All @@ -947,20 +946,22 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp
nil];
[dict addEntriesFromDictionary:errorinfo];
} else {
NSInteger statusCode = [(NSHTTPURLResponse *)[task response] statusCode];

NSMutableDictionary *successResponse = [NSMutableDictionary dictionaryWithObjectsAndKeys:NUMBOOL(YES), @"success",
NUMINT(0), @"errorCode",
@(statusCode), @"statusCode", nil];
NSMutableDictionary *responseObj = [uploadTaskResponses objectForKey:@(task.taskIdentifier)];

if (responseObj != nil) {
// We only send "responseText" as the "responsesData" is only set with data from uploads
NSString *responseText = [[NSString alloc] initWithData:[responseObj objectForKey:@"responseData"] encoding:NSUTF8StringEncoding];
NSInteger statusCode = [[responseObj valueForKey:@"statusCode"] integerValue];

[successResponse setValue:responseText forKey:@"responseText"];
[uploadTaskResponses removeObjectForKey:@(task.taskIdentifier)];
NSDictionary *successResponse = [NSMutableDictionary dictionaryWithObjectsAndKeys:@(YES), @"success",
@(0), @"errorCode",
responseText, @"responseText",
@(statusCode), @"statusCode",
nil];
[dict addEntriesFromDictionary:successResponse];
RELEASE_TO_NIL(responseText);
}
[dict addEntriesFromDictionary:successResponse];
}
[[NSNotificationCenter defaultCenter] postNotificationName:kTiURLSessionCompleted object:self userInfo:dict];
}
Expand Down

0 comments on commit ebae7bd

Please sign in to comment.