[TIMOB-23116] iOS: Add sessionIdentifier to URLSession events
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | Medium |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2016-03-28T17:11:28.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 5.4.0 |
| Components | iOS |
| Labels | ios, nsurlsession, qe-5.4.0, sessionIdentifier |
| Reporter | Hans Knöchel |
| Assignee | Hans Knöchel |
| Created | 2016-03-27T16:02:58.000+0000 |
| Updated | 2016-08-05T17:52:54.000+0000 |
Description
There is a community PR to add the
sessionIdentifier to the URLSession: https://github.com/appcelerator/titanium_mobile/pull/6941
We need to do the following:
* Nil-validations for the case that the sessionIdentifier is nil
* The docs for the new property, as well as the docs for the uploadprogress event
* The missing dictionary in URLSessionDidFinishEventsForBackgroundURLSession.
PR: https://github.com/appcelerator/titanium_mobile/pull/7889
Test-case: 1. Follow [this guide](http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Background_Services-section-37539664_iOSBackgroundServices-URLSessionModule) to use the urlSession module with Titanium 2. Inside the
downloadprogressanddownloadcompletedevent, watch out for thesessionIdentifierproperty when it is called.[~hansknoechel] I am getting an invalid session error when testing the sessionIdentifier.
Error
[ERROR] : Error: invalid session at makeError (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/auth.js:87:14) at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/auth.js:256:21 at Request._callback (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/index.js:354:11) at Request.self.callback (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/request.js:187:22) at emitTwo (events.js:87:13) at Request.emit (events.js:172:7) at Request.<anonymous> (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/request.js:1044:10) at emitOne (events.js:77:13) at Request.emit (events.js:169:7) at IncomingMessage.<anonymous> (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/request.js:965:12) at emitNone (events.js:72:20) at IncomingMessage.emit (events.js:166:7) at endReadableNT (_stream_readable.js:913:12) --------------------------------------------- at Request.init (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/request.js:190:10) at new Request (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/request.js:129:8) at request (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/index.js:55:10) at Function.get (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/index.js:63:12) at _createRequest (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/index.js:429:39) at Function.AppC.createRequest (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/index.js:387:9) at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/auth.js:251:8 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/node_modules/async/lib/async.js:251:17 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/node_modules/async/lib/async.js:154:25 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/node_modules/async/lib/async.js:248:21 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/node_modules/async/lib/async.js:612:34 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/auth.js:110:3 at next (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/tough-cookie/lib/cookie.js:994:9) at MemoryCookieStore.putCookie (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/tough-cookie/lib/memstore.js:118:3) at withCookie (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/tough-cookie/lib/cookie.js:1013:13) --------------------------------------------- at cli.addHook.post (/Users/Josh/Library/Application Support/Titanium/mobilesdk/osx/5.4.0.v20160802165655/iphone/cli/hooks/run.js:52:7) at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/titanium/lib/hook.js:235:13 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/titanium/node_modules/async/lib/async.js:689:13 at iterate (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/titanium/node_modules/async/lib/async.js:265:13) at nextTickCallbackWith0Args (node.js:420:9) at process._tickCallback (node.js:349:13) [ERROR] : Error: invalid session at makeError (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/auth.js:87:14) at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/auth.js:256:21 at Request._callback (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/index.js:354:11) at Request.self.callback (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/request.js:187:22) at emitTwo (events.js:87:13) at Request.emit (events.js:172:7) at Request.<anonymous> (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/request.js:1044:10) at emitOne (events.js:77:13) at Request.emit (events.js:169:7) at IncomingMessage.<anonymous> (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/request.js:965:12) at emitNone (events.js:72:20) at IncomingMessage.emit (events.js:166:7) at endReadableNT (_stream_readable.js:913:12) --------------------------------------------- at Request.init (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/request.js:190:10) at new Request (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/request.js:129:8) at request (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/index.js:55:10) at Function.get (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/request/index.js:63:12) at _createRequest (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/index.js:429:39) at Function.AppC.createRequest (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/index.js:387:9) at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/auth.js:251:8 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/node_modules/async/lib/async.js:251:17 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/node_modules/async/lib/async.js:154:25 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/node_modules/async/lib/async.js:248:21 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/node_modules/async/lib/async.js:612:34 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/appc-platform-sdk/lib/auth.js:110:3 at next (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/tough-cookie/lib/cookie.js:994:9) at MemoryCookieStore.putCookie (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/tough-cookie/lib/memstore.js:118:3) at withCookie (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/tough-cookie/lib/cookie.js:1013:13) --------------------------------------------- at cli.addHook.post (/Users/Josh/Library/Application Support/Titanium/mobilesdk/osx/5.4.0.v20160802165655/iphone/cli/hooks/run.js:52:7) at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/titanium/lib/hook.js:235:13 at /Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/titanium/node_modules/async/lib/async.js:689:13 at iterate (/Users/Josh/.appcelerator/install/5.4.0-38/package/node_modules/titanium/node_modules/async/lib/async.js:265:13) at nextTickCallbackWith0Args (node.js:420:9) at process._tickCallback (node.js:349:13)ENV
App.js used
// Require in the urlSession module var urlSession = require("com.appcelerator.urlSession"); var session; // App UI var win = Ti.UI.createWindow({backgroundColor:"white"}); var progress = Ti.UI.createProgressBar({ width: 200, height: 50, min: 0, max: 1, value: 0, style: Ti.UI.iOS.ProgressBarStyle.PLAIN, top: 10, message: 'Downloading image URL', font: { fontSize: 12, fontWeight: 'bold'}, color: '#888' }); win.add(progress); var imageView = Ti.UI.createImageView({ top:150, height:300, width:200 }); win.add(imageView); var button = Ti.UI.createButton({ title:'Download Image (url)', height:40, width:200, top:70 }); button.addEventListener('click', function() { // Create a session configuration // The string parameter is an arbitrary string used to identify the session in events var sessionConfig = urlSession.createURLSessionBackgroundConfiguration("com.appcelerator.test"); // Create a session session = urlSession.createURLSession(sessionConfig); // Create a background download task to get the asset with the URL urlSession.backgroundDownloadTaskWithURL(session,"https://raw.github.com/appcelerator-developer-relations/KitchenSink/master/Resources/images/dog@2x~iphone.jpg"); progress.show(); }); win.add(button); win.open(); // Monitor this event to receive updates on the progress of the download Ti.App.iOS.addEventListener("downloadprogress", function(e) { // Update the progress indicator progress.value = (e.totalBytesWritten/e.totalBytesExpectedToWrite); Ti.API.info("download progress " + JSON.stringify(e)); }); // Monitor this event to know when the download completes Ti.App.iOS.addEventListener("downloadcompleted", function(e) { Ti.API.info("download completed " + JSON.stringify(e)); // Update the image imageView.image = e.data; // Invalidate the session and cancel current session tasks urlSession.invalidateAndCancel(session); // Notify the user the download is complete if the application is in the background Ti.App.iOS.scheduleLocalNotification({ alertBody:"Download complete!", date:new Date().getTime() }); progress.hide(); }); // Monitor this event to know when all session tasks have completed Ti.App.iOS.addEventListener('sessioncompleted', function(e) { Ti.API.info("sessioncompleted " + JSON.stringify(e)); if (e.success) { alert("Downloads completed successfully."); } });[~jlongton] The error log you are showing seems like it's involved with appc-platform-sdk, may not have anything to do with this ticket. Can you verify: 1. If you are on preprod or prod 2. Try using appc cli core 5.3.1
Verified as fixed, the error is not present now. Tested on:
*Closing ticket*