ios - NSURLSession 什么时候运行?

标签 ios push-notification nsurlconnection nsurlsession

我有一种情况,当设备收到推送通知时,我会发送一个 NSURLSession 和一个 NSURLConnection。我有几个关于 NSURLSession 的问题。

如果互联网连接丢失,NSURLSession 的 数据任务是否会在后台自动恢复?

如果最初没有互联网,NSURLSession 会自动尝试完成任务,还是 session 只是返回错误?

最佳答案

看来要由您来处理重试了。

When any task completes, the NSURLSession object calls the delegate’s URLSession:task:didCompleteWithError: method with either an error object, or nil if the task completed successfully. If the task is a resumable download task, the NSError object’s userInfo dictionary contains a value for the NSURLSessionDownloadTaskResumeData key. Your app should use reachability APIs to determine when to retry, and should then call downloadTaskWithResumeData: or downloadTaskWithResumeData:completionHandler: to create a new download task to continue that download. Go to step 3 (creating and resuming task objects).

https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/URLLoadingSystem/NSURLSessionConcepts/NSURLSessionConcepts.html

关于ios - NSURLSession 什么时候运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19236440/

相关文章:

ios - 防止 180 度翻转 iOS Cordova

android - 如何在 android 中启用和禁用 GCM?

iphone - NSURLConnection 和中央调度

iphone - NSURLRequest 委托(delegate)未在设备上被调用在模拟器上工作正常。

ios - UITableView 部分重复数据

ios - 如何重构此代码,以便在Swift中变量之间仅共享某些属性

ios - UIPasteboard 在哪里存储数据?

ios - 如何确保通过网络接收到请求? (以店员为例)

ios - 与多个开发人员进行代码签名

ios - 旧 View 的线程仍在运行