ios – NSURLSession何时运行?

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

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

如果最初没有互联网,NSURLSession是否会自动尝试完成任务,或者会话是否因错误而返回?

解决方法

看起来你需要处理重试.

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 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...