How long does Apple permit a background task to run?

The amount of time will differ based on many different variables, but the value can be checked by referencing the backgroundTimeRemaining property on UIApplication:

NSLog(@"Time Remaining: %f", [[UIApplication sharedApplication] backgroundTimeRemaining]);

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+:

iOS version pre 7

The answer is simply 600 seconds (10 minutes), reason is provided by the article above.

iOS version 7+

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.

Tags:

Ios

Iphone