Reputation: 550
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??
Upvotes: 0
Views: 171
Reputation: 13192
It is possible to download assets when your application is not active only and only if your app has periodically updated content like magazines and newspapers. In this case you can use the Newsstand framework.
Upvotes: 0
Reputation: 51
Yes this can't be done, I'll suggest when application goes background if any download connection exists better to cancel it & start the download again when application comes foreground. Other possibility we need to maintain a pause & resume, This required some server changes also.
This may helpful:
How to pause/resume downloads in iPhone (iOS)
Upvotes: 0