I am working with the app in which i want to download data in background. As per Apple multitasking guidelines, you are allowed to download data for 10 minutes.
In my case, it will take more than 10 minutes for downloading file and downloading get failed.
Initial downloading request is from DownloadViewController as below.
- (IBAction)performLargeUpload:(id)sender {
[request cancel];
[self setRequest:[ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://mirrorblender.top-ix.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_stereo.avi"]]]; // 149MB
[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"big_buck_bunny_480p_stereo.avi"]];
[request setTimeOutSeconds:20];
[request setDownloadProgressDelegate:progressIndicator];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
[request setShouldContinueWhenAppEntersBackground:YES];
#endif
[request setDelegate:self];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setDidFinishSelector:@selector(uploadFinished:)];
[request setAllowResumeForFileDownloads:YES];
[request startAsynchronous];
[resultView setText:@"Downloading data..."];
}
In appDelegate, i have put this code When applicationDidEnterBackground
- (void)applicationDidEnterBackground:(UIApplication *)application {
UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier bgTask;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
backgroundTimer=nil;
backgroundTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(keepAlive) userInfo:nil repeats:YES];
}
How to extend the time for background downloading??