Download large files that take more than 10 minutes when the iPad is locked

I have a requirement where a user can upload multiple files one by one. When my application leaves in the background or when the iPad is locked, a response to a download or web service can be received only within 10 minutes.

My download takes place in a separate thread, I implemented beginBackgroundTaskWithExpirationHandler: after some searches and links to stackoverflow.

How to implement task completion

Application error due to auto lock in iphone?

and iOS documetation

https://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

Now some of my selected files are downloaded, and some of them do not work, because you can complete the background task for only 10 minutes.

Is there an alternative for this? Should I pause the download completely while the application is running in the background? Can anyone help me in this regard?

I managed to do this without ending with a background task if my download is in progress.

bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ NSLog(@"\n beginBackgroundTaskWithExpirationHandler called \n"); if(![self checkIfDownloadInProgress]){ [self endTaskOnCompletion]; } }];

This only works if the device is manually locked by the user. If the device locks automatically after 2 minutes, the application starts for 10 minutes, and then it crashes. Can someone help?

+4
source share
2 answers
  • If not necessary, stop it. This is the best you can do.
  • Else , when the expiration handler is called, you can run the background job again and you will get another 10 minutes.
0
source

The only way I found this is possible:

  • Use renewable translations, upload / download to chunks.
  • When the app is sent to the background, continue transferring for 10 minutes
  • Timed cleaning
  • Resume transfer upon application activation.

This document pretty much summarizes possible online solutions and multitasking: https://developer.apple.com/library/ios/#technotes/tn2277/_index.html

0
source

Source: https://habr.com/ru/post/1398000/


All Articles