ios – NSURLSession何时运行?

前端之家收集整理的这篇文章主要介绍了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相关文章