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