NSURLSession
seems like a great new API. Sadly, documentation is still lacking.
NSURLSession似乎是一个很棒的新API。可悲的是,文档仍然缺乏。
I am planning on supporting NSURLSession
background modes. I read that, these tasks will only download on the Apple daemon if the user is connected over Wifi, and if he has sufficient battery remaining. So if I queue some tasks, and the aforementioned conditions are not met, the task will await until they are. But what happens if the user opens the application and the data is missing? Will the pending tasks execute despite lack of wifi or low battery? Should I be cancelling them and starting them as data tasks in-process? I am aware of the discretionary
property, but would tasks scheduled in the background start once the app is launched/resumed?
我打算支持NSURLSession后台模式。我读过,如果用户通过Wifi连接,并且剩余电量充足,这些任务只会在Apple守护程序上下载。因此,如果我排队某些任务,并且不满足上述条件,则任务将等待直到它们为止。但是如果用户打开应用程序并且数据丢失会发生什么?即使没有wifi或电池电量不足,待执行的任务是否会执行?我应该取消它们并将它们作为数据任务启动吗?我知道*选择的属性,但是一旦应用程序启动/恢复,后台安排的任务会启动吗?
1 个解决方案
#1
2
You will either be resuming from background, or starting new again.
您将从后台恢复,或重新开始新的。
If resuming from background, the background NSURLSession
should complete the tasks you queued, so long as you "retain/retained" it. My experience is background sessions work just fine in foreground, they are just limited (e.g. no data tasks).
如果从后台恢复,后台NSURLSession应该完成您排队的任务,只要您“保留/保留”它即可。我的经验是后台会话在前台工作得很好,它们只是有限的(例如没有数据任务)。
If starting anew, you can "rewire" your background session by using the same configuration NSString
you used, e.g.
如果重新开始,您可以使用您使用的相同配置NSString“重新连接”后台会话,例如
NSURLSessionConfiguration config =
[NSURLSessionConfiguration backgroundSessionConfiguration:sameStringHere];
Once "rewired", it should keep rolling.
一旦“重新布线”,它应该继续滚动。
Agreed about the docs.
同意文档。
#1
2
You will either be resuming from background, or starting new again.
您将从后台恢复,或重新开始新的。
If resuming from background, the background NSURLSession
should complete the tasks you queued, so long as you "retain/retained" it. My experience is background sessions work just fine in foreground, they are just limited (e.g. no data tasks).
如果从后台恢复,后台NSURLSession应该完成您排队的任务,只要您“保留/保留”它即可。我的经验是后台会话在前台工作得很好,它们只是有限的(例如没有数据任务)。
If starting anew, you can "rewire" your background session by using the same configuration NSString
you used, e.g.
如果重新开始,您可以使用您使用的相同配置NSString“重新连接”后台会话,例如
NSURLSessionConfiguration config =
[NSURLSessionConfiguration backgroundSessionConfiguration:sameStringHere];
Once "rewired", it should keep rolling.
一旦“重新布线”,它应该继续滚动。
Agreed about the docs.
同意文档。