Reputation: 1208
I'm downloading big file ~50-100Mb with help of AFNetworking, and I want to save it's download state on app termination to resume download later. I've registered my object to terminate notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillTerminate) name:UIApplicationWillTerminateNotification object:nil];
this method called when user closing app from app switcher:
-(void)appWillTerminate {
NSLog(@"---------- will terminate");
[downloadTask cancelByProducingResumeData:^(NSData *resumeData) {
if(resumeData) {
[self saveResumeData:resumeData];
} else {
[[NSFileManager defaultManager] removeItemAtPath:[self createCachePath] error:nil];
}
}];
}
but this block: ^(NSData *resumeData)
is never called so I can not save resume data.
Also this method not called at all when app was firstly moved to background and then closed.
I do not want to call this method on entering background, because I want to continue downloading. Is there something I'm doing wrong?
Upvotes: 3
Views: 1466
Reputation: 231
Try to change logic: add “pause button”, if user wants to close the app he will firstly need to pause download and then close the app. In case user will ignore pausing, it’s not a problem to resume downloading from position you have saved earlier or from the beginning. Main thing here - continue downloading in background.
Upvotes: 1