How to resume NSURLSession download process after app force-quit and app relaunch?

牧云@^-^@ 提交于 2019-12-02 20:44:57
Fabio Felici

After a force-quit the:

 NSURLSessionTaskDelegate - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error

delegate method will be called when the app is restarted. If the download task can be resumed the error object will contain the resume data:

[error.userInfo objectForKey:NSURLSessionDownloadTaskResumeData].

Using this data you can resume the download process by creating a NSURLSessionDownloadTask with:

(NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData*)resumeData.

More info about that can be found in Life Cycle of a URL Session with Custom Delegates, step 13.

I think that after your application did force-quit you should start all over again (.

If the user terminates your app, the system cancels any pending tasks.

and

When all of the tasks associated with a background session are complete, the system relaunches a terminated app (assuming that the sessionSendsLaunchEvents property was set to YES and that the user did not force quit the app)

https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

-> use URLSession background Sessions download doesn't stop at all....you don't have to explicitly code for resuming the download or something..

https://developer.apple.com/reference/foundation/urlsession

check for background session in this link...if you're not able get the still...comment me and i would help in detail.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!