Since the answer is long, am updating as a answer.
As per the Apple’s documentation on Background Execution, it says:
Suppose if you are running a process and in between you press the home button and your app goes to the background, then your app should get some time to finish what it was doing or at least in most cases it should be able to save any important data. This is where you are requesting the os for the background execution.
Normally the OS will give upto 3 minutes(180 seconds) to complete the task . This is just a general observation. The time can be greater than or less than 3 minutes.This is not given in the official documentation.
If you don’t call endBackgroundTask() after a period of time in the background, your app will be terminated. you will end up in losing the upload.
Idea:
- If your task not being finished in the allocated time (3 minutes), you can post some local notification to the user states "open you application to resume the upload"
- you can upload by batches (dropbox uses chunkers to upload or update the data)
- if you take a look at whatsapp, google photos. it will alert you when you going to background while uploading.
- Before uploading, check if the data is huge then alert user. if the accept it the upload it.
- Have option to upload only on wifi
WARNINIG: There is no way of doing the infinite or long running task in the background