Continue uploading process in background IOS

13,235

Solution 1

You need to ask the OS to keep the app running, it has nothing to do with Dropbox... When you start uploading, do this:

UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
    [[UIApplication sharedApplication] endBackgroundTask:bgTask];
}];

... and store the bgTask somewhere. Then when your upload completes or fails, do this:

[[UIApplication sharedApplication] endBackgroundTask:bgTask];

That will tell the OS to keep your app running because there's a background task running...

Solution 2

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

By requesting, it means that when your App Delegate method applicationDidEnterBackground gets called you have about 5 seconds to finish up. As you are doing a long upload, you can request additional time via beginBackgroundTaskWithExpirationHandler

Share:
13,235
Alessandro
Author by

Alessandro

Updated on June 22, 2022

Comments

  • Alessandro
    Alessandro about 2 years

    I was wondering if it was possible to continue the uploading of a file in the background. for example when the user puts the iPad in sleep, the uploading continues...

    I asked this question in the dropbox forums as well since I am uploading to dropbox using the core API. This was the answer:

    "Using the core API, uploading is entirely in the control of your app. You can request that the OS keep your app alive in the background, which it will allow for a maximum of 10 minutes before suspending your app. You can see more information here: https://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html If you use the new Sync API, this will all be done automatically by the API."

    I am posting here because I didn't understand what they mean by 'request that the OS keep your app alive in the background'. Does this mean I have to request the ios wi a specific code, and it has nothing to do with dropbox, or it is a particular dropbox function?