Continue uploading process in background IOS

痴心易碎 提交于 2020-01-19 07:30:06

问题


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:


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




回答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




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/15788106/continue-uploading-process-in-background-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!