I need to download files> 500 Mo with AFNetworking. Sometimes their download time is> 10 minutes, and if the application is in the background, the download cannot be completed.
So, I want to try partial download. I found a lot of links, and this seems possible using the pause () and resume () methods in AFHTTPRequestOperation.
Actually, I did:
[self.downloadOperation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{ // Clean up anything that needs to be handled if the request times out [self.downloadOperation pauseDownload]; }];
DownloadOperation is a subclass of AFHTTPRequestOperation (singleton).
And in AppDelegate:
- (void)applicationWillEnterForeground:(UIApplication *)application {
Server ok to get new range in headers ...
My questions:
1) Isnβt a good way to do this? 2) Is a summary required to change outputStream (add: NO => append: YES)? Or is it somewhere controlled by AFNetworking? (can not found)
self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:YES];
Something like this (in DownloadHTTPRequestOperation):
- (void)pauseDownload { NSLog(@"pause download"); [self pause]; } - (void)resumeDownload { NSLog(@"resume download"); self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:YES]; [self resume]; }
Thanks for your help.
source share