D
D
deleted-mezhevikin2013-11-13 18:09:09
Objective-C
deleted-mezhevikin, 2013-11-13 18:09:09

Saving downloaded data to NSURLSessionDownloadTask when app process terminates?

Found a good example of working with the new NSURLSession : iOS7_Multitasking .
The example implements the function of stopping the download and saving resumeData for subsequent resuming:

- (void) stopDownloadWithTaskIdentifier:(NSUInteger)taskIdentifier
{
    KDownloadInfo *di = [self.downloadInfoDictionary objectForKey:kDownloadInfoKey(taskIdentifier)];
    if (di && di.downloadTask) {
        [di.downloadTask cancelByProducingResumeData:^(NSData *resumeData) {
             NSLog(@"RESUME DATA %@", resumeData);
            if (resumeData) {
                di.resumeData = resumeData;
            }
        }];
    }
}

If you start loading and call the method by tapping on the stop button, then resumeData in the cancelByProducingResumeData handler will not be empty.
If you call the method on the UIApplicationWillTerminateNotification event, that is, start loading and kill the application process, then resumeData is always empty.
Why is this happening and how can I make sure that the loading process is saved when the application ends?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question