Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): event sessioncompleted does not get all specified values #11782

Merged
merged 6 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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