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

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


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.