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

前端 未结 3 1941
傲寒
傲寒 2021-02-02 13:00

I have implemented NSURLSession for downloading fairly large files from our servers. Now as long as I\'m working in foreground or background and go back to the app

相关标签:
3条回答
  • 2021-02-02 13:47

    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

    0 讨论(0)
  • 2021-02-02 13:53

    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.

    0 讨论(0)
  • 2021-02-02 13:55

    -> 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.

    0 讨论(0)
提交回复
热议问题