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

[TIMOB-23116] iOS: Add session identifiers to urlSession events #7889

Merged
merged 4 commits into from
Mar 28, 2016
Merged
Show file tree
Hide file tree
Changes from 3 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
67 changes: 57 additions & 10 deletions apidoc/Titanium/App/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ methods:
parameters:
- name: handlerID
summary: |
Unique string identifer for the event (`backgroundfetch`, `silentpush` or `backgroundtransfer`)
Unique string identifier for the event (`backgroundfetch`, `silentpush` or `backgroundtransfer`)
that initiated the background opertation mode.
type: String
osver: {ios: {min: "7.0"}}
Expand All @@ -191,7 +191,7 @@ methods:
parameters:
- name: handlerId
summary: |
Unique string identifer for the event (`watchkitextensionrequest`)
Unique string identifier for the event (`watchkitextensionrequest`)
that initiated from the WatchKit extension calling the openParentApplication:reply method.
type: String
- name: userInfo
Expand Down Expand Up @@ -748,7 +748,7 @@ events:
properties:
- name: handlerId
summary: |
Unique string identifer for the `backgroundfetch` event. This identifier should be passed as the argument
Unique string identifier for the `backgroundfetch` event. This identifier should be passed as the argument
to the [endBackgroundHandler](Titanium.App.iOS.endBackgroundHandler) method.
type: String
platforms: [iphone, ipad]
Expand Down Expand Up @@ -789,7 +789,7 @@ events:
properties:
- name: handlerId
summary: |
Unique string identifer for the `silentpush` event. This identifier should be passed as the argument
Unique string identifier for the `silentpush` event. This identifier should be passed as the argument
to the [endBackgroundHandler](Titanium.App.iOS.endBackgroundHandler) method.
type: String
platforms: [iphone, ipad]
Expand Down Expand Up @@ -825,7 +825,7 @@ events:
properties:
- name: handlerId
summary: |
Unique string identifer for the `backgroundtransfer` event. This identifier should be passed as the argument
Unique string identifier for the `backgroundtransfer` event. This identifier should be passed as the argument
to the [endBackgroundHandler](Titanium.App.iOS.endBackgroundHandler) method.
type: String
- name: sessionId
Expand All @@ -845,9 +845,13 @@ events:
This event only needs to be used if your app is using the `urlSession` module to download data.
properties:
- name: taskIdentifier
summary: The `urlSession` download task's identifer.
summary: The `urlSession` download task's identifier.
type: Number

- name: sessionIdentifier
summary: The `urlSession` session identifier. If it does not exist, this property is not provided.
type: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not add since to this property ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the problem is, that event properties cannot have the since property. I added it to the summary.


- name: bytesWritten
summary: The number of bytes transferred since the last time this event was fired.
type: Number
Expand All @@ -864,6 +868,37 @@ events:
osver: {ios: {min: "7.0"}}
since: "3.2.0"

- name: uploadprogress
summary: |
Fired periodically to inform the app about the upload's progress of a [urlSession](Modules.URLSession).
Available only on iOS 7 and later.
description: |
This event only needs to be used if your app is using the `urlSession` module to upload data.
properties:
- name: taskIdentifier
summary: The `urlSession` upload task's identifier.
type: Number

- name: sessionIdentifier
summary: The `urlSession` session identifier. If it does not exist, this property is not provided.
type: String

- name: bytesSent
summary: The number of bytes transferred since the last time this event was fired.
type: Number

- name: totalBytesSent
summary: The total number of bytes transferred so far.
type: Number

- name: totalBytesExpectedToSend
summary: |
The expected length of the file, as provided by the Content-Length header. If this
header was not provided, the value is zero.
type: Number
osver: {ios: {min: "7.0"}}
since: "3.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im guessing this was always in the code but missed from the docs ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, since 3.2.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, awesome :)


- name: downloadcompleted
summary: |
Fired to indicate that a [urlSession's](Modules.URLSession) download task has finished downloading.
Expand All @@ -872,9 +907,13 @@ events:
This event only needs to be used if your app is using the `urlSession` module to download data.
properties:
- name: taskIdentifier
summary: The `urlSession` download task's identifer.
summary: The `urlSession` download task's identifier.
type: Number

- name: sessionIdentifier
summary: The `urlSession` session identifier. If it does not exist, this property is not provided.
type: String

- name: data
summary: The downloaded data as a Titanium.Blob object.
type: Titanium.Blob
Expand All @@ -893,9 +932,13 @@ events:
the hostname or connect to the host.
properties:
- name: taskIdentifier
summary: The `urlSession` download task's identifer.
summary: The `urlSession` download task's identifier.
type: Number

- name: sessionIdentifier
summary: The `urlSession` session identifier. If it does not exist, this property is not provided.
type: String

- name: success
summary: Indicates if the operation succeeded. Returns true if download succeeded, false otherwise.
type: Boolean
Expand Down Expand Up @@ -929,6 +972,10 @@ events:
is now safe to invoke [endBackgroundHandler](Titanium.App.iOS.endBackgroundHandler)
method with the `handlerID` or to begin any internal updates that may result in invoking
this method.
properties:
- name: sessionIdentifier
summary: The `urlSession` session identifier. If it does not exist, this property is not provided.
type: String
osver: {ios: {min: "7.0"}}
since: "3.2.0"

Expand Down Expand Up @@ -970,7 +1017,7 @@ events:
properties:
- name: handlerId
summary: |
Unique string identifer for the `watchkitextensionrequest` event. This identifier should be passed an argument
Unique string identifier for the `watchkitextensionrequest` event. This identifier should be passed an argument
to the [sendWatchExtensionReply](Titanium.App.iOS.sendWatchExtensionReply) method.
type: String
- name: userInfo
Expand All @@ -995,7 +1042,7 @@ events:
properties:
- name: activityType
summary: |
Unique string identifer for the handoff user activity. The identifier must be defined in your `tiapp.xml` file.
Unique string identifier for the handoff user activity. The identifier must be defined in your `tiapp.xml` file.
type: String
- name: searchableItemActivityIdentifier
summary: |
Expand Down
35 changes: 31 additions & 4 deletions iphone/Classes/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -715,19 +715,30 @@ -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask
else {
downloadedData = [[[TiBlob alloc] initWithFile:[destinationURL path]] autorelease];
}
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithUnsignedInteger:downloadTask.taskIdentifier ],@"taskIdentifier",downloadedData,@"data", nil];

NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithUnsignedInteger:downloadTask.taskIdentifier ],@"taskIdentifier",
downloadedData,@"data", nil];

if (session.configuration.identifier) {
[dict setObject:session.configuration.identifier forKey:@"sessionIdentifier"];
}

[[NSNotificationCenter defaultCenter] postNotificationName:kTiURLDownloadFinished object:self userInfo:dict];
}

-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
{

//FunctionName();
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithUnsignedInteger:downloadTask.taskIdentifier], @"taskIdentifier",
[NSNumber numberWithUnsignedLongLong:bytesWritten], @"bytesWritten",
[NSNumber numberWithUnsignedLongLong:totalBytesWritten], @"totalBytesWritten",
[NSNumber numberWithUnsignedLongLong:totalBytesExpectedToWrite], @"totalBytesExpectedToWrite", nil];

if (session.configuration.identifier) {
[dict setObject:session.configuration.identifier forKey:@"sessionIdentifier"];
}

[[NSNotificationCenter defaultCenter] postNotificationName:kTiURLDowloadProgress object:self userInfo:dict];

}
Expand All @@ -739,6 +750,11 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSend
[NSNumber numberWithUnsignedLongLong:bytesSent], @"bytesSent",
[NSNumber numberWithUnsignedLongLong:totalBytesSent], @"totalBytesSent",
[NSNumber numberWithUnsignedLongLong:totalBytesExpectedToSend], @"totalBytesExpectedToSend", nil];

if (session.configuration.identifier) {
[dict setObject:session.configuration.identifier forKey:@"sessionIdentifier"];
}

[[NSNotificationCenter defaultCenter] postNotificationName:kTiURLUploadProgress object:self userInfo:dict];
}

Expand All @@ -749,6 +765,11 @@ -(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompl
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithUnsignedInteger:task.taskIdentifier], @"taskIdentifier",
nil];

if (session.configuration.identifier) {
[dict setObject:session.configuration.identifier forKey:@"sessionIdentifier"];
}

if (error) {
NSDictionary * errorinfo = [NSDictionary dictionaryWithObjectsAndKeys:NUMBOOL(NO), @"success",
NUMINTEGER([error code]), @"errorCode",
Expand All @@ -774,7 +795,13 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas

- (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
{
[[NSNotificationCenter defaultCenter] postNotificationName:kTiURLSessionEventsCompleted object:self userInfo:nil];
NSDictionary *dict = nil;

if (session.configuration.identifier) {
dict = @{@"sessionIdentifier": session.configuration.identifier};
}

[[NSNotificationCenter defaultCenter] postNotificationName:kTiURLSessionEventsCompleted object:self userInfo:dict];
}

#pragma mark
Expand Down