I have to upload an array of image files to database, therefore, I stumbled upon Apple's background execution guide to make sure the app still uploads the data when user suspends or terminates my app.
But in the desciption, it says giving it a little extra time to finish its work
if we call beginBackgroundTaskWithName:expirationHandler:
or beginBackgroundTaskWithExpirationHandler:
to start a background task.
How long is little extra time
precisely?
Tasks are under a strict time limit, and typically get about 600 seconds (10 minutes) of processing time after an application has moved to the background on iOS 6, and less than 10 minutes on iOS 7+.
The only apps that are really running in the background are music or navigation apps. Go to Settings>General>Background App Refresh and you can see what other apps are allowed to update data in the background. iOS dynamically manages memory without any user intervention. Thank you!
You still should use foreground services to perform tasks that are long running and need to notify the user that they are ongoing. If you use foreground services directly, ensure you shut down the service correctly to preserve resource efficiency.
Overview. Use the BackgroundTasks framework to keep your app content up to date and run tasks requiring minutes to complete while your app is in the background. Longer tasks can optionally require a powered device and network connectivity.
Correct me if I am wrong, but I have stumbled upon a perfect article from Xamarin that discusses iOS backgrounding feature.
I will simply break down to two parts, ios pre 7 and ios 7+:
The answer is simply
600
seconds (10 minutes), reason is provided by the article above.
The answer is that the time system allocates you is opportunistic. You will have to use @Gary Riches's suggestion
NSLog(@"Time Remaining: %f", [[UIApplication sharedApplication] backgroundTimeRemaining]);
to find out. The reason for it being opportunistic is the way iOS 7+ handles background tasks is completely different, certainly optimised. To be exact, It has an intermittent behaviour, and therefore, if you need background tasks such as downloading a big chuck of data, it will be much more effective if you use
NSURLSession
instead.
However, in my special case, I am uploading one single object that contains one file to be exact. I do not have to consider NSURLSession
for uploading a small amount of data. And besides, it's uploading task, it can take as much time as it wants. :-)
For these TL;DR
visitors, the answer above should be sufficient. For more details, please refer to the article above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With