6

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?

1
  • Can you link to your question in dropbox forum? Jul 11, 2013 at 10:22

4 Answers 4

24

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...

5
  • 3
    It's important to mention that: "Each task you mark will have roughly 10 minutes (total) to complete its actions, plenty of time for most common uses. After the time completes, the application is suspended and treated like any other suspended application." (Quoted from this link: codeproject.com/Articles/124159/…)
    – Eli Ganem
    Apr 3, 2013 at 14:36
  • Thanks, very neat answer, but I have a doubt: how can I determine if the uploadis complete if I am not in the app itself? Wont other functions of my app be blocked? Can I insert the endBackgroundTask call in a normal void method?
    – Alessandro
    Apr 3, 2013 at 15:21
  • Yes if you've called the first function while your app was in the foreground then when it enters the background it'll continue to run normally until you call the second function to let the system know that you're done...
    – jjv360
    Apr 3, 2013 at 18:07
  • And can you launch multiple background tasks at the same time? Imagine you want to upload five different files, if you create a new instance of the UIBackgroundTaskIdentifier for each of them, will the other 4 continue when the 1st one calls endBackgroundTask?
    – Jules
    Aug 28, 2013 at 12:06
  • @Jules Yep, just remember to call endBackgroundTask for each one
    – jjv360
    Aug 28, 2013 at 16:14
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

0

New Dropbox SDK provides the functionality of background uploading/Downloading of files. Please try using new SDK. Have a happy coding.

2
  • Are you talking about the Dropbox iOS SDK? Because I can't find the support for uploading/downloading files in background in the latest version 1.3.5.
    – Dev
    Aug 19, 2013 at 9:13
  • Then try by using beginBackgroundTaskWithExpirationHandler for uploading/downloading.. This might help you out. Aug 24, 2013 at 9:51
-3

I guess this worked for me.

  1. disabled autolock
  2. disabled screentimeout
  3. plugged in to power
  4. Enable location services on iphone for dropbox and background running option
  5. left the dropbox app open
  6. more than 2000 photos & videos upload successfully

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.