Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19979] iOS: Improvements on the ti.urlsession module

GitHub Issuen/a
TypeImprovement
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
LabelsCommunity
ReporterShawn Lan
AssigneeUnknown
Created2015-08-06T18:39:21.000+0000
Updated2018-02-28T19:56:00.000+0000

Description

1. Right now with URLSession module, you can invalidate the entire session, but cannot cancel a single task. Please add this ability to the module. 2. Please expose [allowsCellularAccess](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSessionConfiguration_class/#//apple_ref/occ/instp/NSURLSessionConfiguration/allowsCellularAccess). The default is true. It's useful sometimes to set it false. Thanks. Test case: - create a default Alloy project. Add URLSession Module. Use the following code: index.js
var urlSession,sessionConfig,session;

function doClick(e) {
    urlSession = require("com.appcelerator.urlSession");
	sessionConfig = urlSession.createURLSessionBackgroundConfiguration("com.appcelerator.session");
	session = urlSession.createURLSession(sessionConfig);
	urlSession.backgroundDownloadTaskWithURL(session, "http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_50mb.mp4");
	urlSession.backgroundDownloadTaskWithURL(session, "http://www.sample-videos.com/video/mp4/480/big_buck_bunny_480p_50mb.mp4");
}

function doClick2(e){
	urlSession.invalidateAndCancel(session);
}

$.index.open();

Ti.App.iOS.addEventListener('downloadprogress',function(e){
	Ti.API.info(e.type);
});
Ti.App.iOS.addEventListener('downloadcompleted',function(e){
	Ti.API.info(e.type);
});
Ti.App.iOS.addEventListener('sessioncompleted',function(e){
	Ti.API.info(e.type);
});
index.xml
<Alloy>
	<Window class="container">
		<Label id="label" onClick="doClick">Click to initiate two tasks</Label>
		<Label id="label2" onClick="doClick2">Click to cancel two tasks</Label>
	</Window>
</Alloy>
index.tss
".container": {
	backgroundColor:"white"
}

"Label": {
	width: Ti.UI.SIZE,
	height: Ti.UI.SIZE,
	color: "#000"
}

"#label": {
	font: {
		fontSize: 12
	},
	top:50
}

"#label2": {
	font: {
		fontSize: 12
	}
}
- Click to download two files at the same time, and then click to cancel them all. You can only cancel them all, not individually.

Comments

  1. Radamantis Torres-Lechuga 2015-08-07

    [~shawnlan] can you please add a test case and more details about this? Thanks
  2. Shawn Lan 2015-08-07

    This is not a bug. You can use any example here: http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Background_Services Right now, to cancel a download, you can use either finishTasksAndInvalidate( session ) or invalidateAndCancel( session ). Both cancel the entire session (all tasks running in that session are cancelled). Apple's NURLSession actually allows to cancel individual tasks without canceling the whole session. Please expose those methods in TiSDK. Thank you!
  3. Radamantis Torres-Lechuga 2015-08-07

    [~shawnlan] I know this is not a bug, but still I need to send an example to our engineering team on how the URLSession module works as today and an explanation on how the improvement will help, a use case will be very helpful. Thanks
  4. Shawn Lan 2015-08-21

    Okay, test case added. Please see the updated description. Thanks.

JSON Source