在后台IOS中继续上传过程 [英] Continue uploading process in background IOS

查看:162
本文介绍了在后台IOS中继续上传过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能在后台继续上传文件。例如,当用户将iPad置于睡眠状态时,上传仍会继续...

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

我也是在Dropbox论坛中问了这个问题,因为我是使用核心API。答案就是这样:

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

使用核心API,上传完全在您的应用程序中。您可以要求操作系统在后台让您的应用程序处于活动状态,最多可暂停10分钟,然后再挂起您的应用。您可以在此处查看更多信息:
https://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
如果使用新的Sync API,所有这些操作都将由该API自动完成。

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

我之所以在此发布,是因为我不理解请求操作系统是什么意思。让您的应用在后台运行。这是否意味着我必须向ios请求特定的代码,并且与Dropbox无关,或者它是特定的Dropbox函数?

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?

推荐答案

您需要让操作系统保持运行状态,与Dropbox无关...开始上载时,请执行以下操作:

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];
}];

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

这篇关于在后台IOS中继续上传过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆