0

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??

tamasgal
  • 24,826
  • 18
  • 96
  • 135
Apple
  • 550
  • 3
  • 10
  • 1
    You can't extend the time. You should think about some possibility to resume the download or compress the data etc. – tamasgal May 10 '13 at 06:44
  • check http://stackoverflow.com/a/9412797/1106035 – Paresh Navadiya May 10 '13 at 06:47
  • possible duplicate of [Download large files which takes more than 10 min when iPad device is locked](http://stackoverflow.com/questions/9411122/download-large-files-which-takes-more-than-10-min-when-ipad-device-is-locked) – Prof. Falken May 10 '13 at 06:48
  • But when the endBackgroundTask is called or after 10 min in background, we can pause the download, and in keepAlive method we can resume the downloading, so we can get another 10 minutes. Right?? – Apple May 10 '13 at 06:57

3 Answers3

1

You can't do it. Stop trying.

borrrden
  • 33,256
  • 8
  • 74
  • 109
0

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)

Community
  • 1
  • 1
ram.Iphone
  • 51
  • 4
0

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.

MrTJ
  • 13,064
  • 4
  • 41
  • 63
  • But, I think for periodically updated content, we must use the Newsstand framework, but what about the application without newsstand?? But i want to download periodically updated content without using Newsstand framework in the background. – Apple May 10 '13 at 08:07
  • Finally, with ASIHTTP you can download the content in background more than 10 minutes. It works for me – Apple May 10 '13 at 10:59