在iOS 7+上,如何强制由系统而不是应用程序运行下载操作? [英] on iOS 7+, how to force a download operation to be run by the system rather than the app?

查看:100
本文介绍了在iOS 7+上,如何强制由系统而不是应用程序运行下载操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试iOS 7+应用程序中大型文件的后台下载.

I am wanting to test background downloads of large files in iOS 7+ applications.

我正在使用具有NSURLSession的背景配置,如

I am using a NSURLSession with a background configuration as explained in the Apple documentation on Background Execution.

文档指出:配置完成后,您的NSURLSession对象将在适当的时间无缝地将上载和下载任务传递到系统."

The documentation states that "Once configured, your NSURLSession object seamlessly hands off upload and download tasks to the system at appropriate times."

我正在尝试创建适当的时间,以便可以在发布前测试应用程序.各种示例表明,我可以简单地将一个不同的应用程序带到前台,以触发后台下载任务移交给系统.

I am trying to for the creation of such appropriate times so that I can test an app before release. Various examples suggest that I can simply bring a different application to the foreground to trigger handover of the background download task to the system.

然而,事实并非如此.而是在应用程序的控制下完成下载.

However, that is not proving to be the case. Instead, the download completes under the control of the app.

重要

- (void)application:(UIApplication *)application
handleEventsForBackgroundURLSession:(NSString *)identifier
  completionHandler:(void (^)(void))completionHandler

从不在我的应用程序委托中运行.

never runs in my application delegate.

我试图在iOS模拟器和实际设备上都强制切换,但是没有运气.

I have tried to force a handover on both the iOS simulator and on actual devices but with no luck.

对于强制将后台下载切换到系统的方法的想法,将不胜感激.

Thoughts on ways to force handover to of background downloads to the system would be appreciated.

推荐答案

没有移交".后台会话中的每个任务始终都在单独的过程中运行.

There is no "handover". Every task in a background session always runs in a separate process, period.

application:handleEventsForBackgroundURLSession:completionHandler:方法仅在下载过程中被操作系统终止时(用户)终止运行.如果发生这种情况,只要下载完成,您的应用就会在后台重新启动.

The application:handleEventsForBackgroundURLSession:completionHandler: method, however, runs only if your app gets terminated by the OS (not by the user) while a download is in progress. If this happens, your app gets relaunched in the background whenever the download finishes.

您可以通过在后台开始大量下载来进行测试,该下载将花费很长的时间才能完成您的应用程序的驱逐...或通过切换到另一个在RAM上放出直到您的应用程序驱逐的应用程序.

You can potentially test this by starting a large download in the background that will take long enough to complete that your app will get evicted... or by switching to another app that pigs out on RAM until your app gets evicted.

这篇关于在iOS 7+上,如何强制由系统而不是应用程序运行下载操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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