iphone之在多任务模式下下载大数据

cloudgamer 阅读:36 2025-06-02 22:19:02 评论:0

我正在一个单独的 View Controller 中从 ASynchronous NSURLConnection 下载大数据。下载数据需要 2 分钟。它工作正常。但是当我通过退出应用程序进入后台模式并再次打开时,启动画面出现了
应用程序强制关闭。当下载小数据时,它在同一 View Controller 的后台模式下工作正常。我在阅读苹果的有限长度文档后使用以下代码。
但它不工作?有什么帮助吗?

 - (void)applicationDidEnterBackground:(UIApplication *)application 
 { 
 
    UIApplication  *app = [UIApplication sharedApplication]; 
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{  
      [app endBackgroundTask:bgTask];  
      bgTask = UIBackgroundTaskInvalid; 
    }]; 
 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{}); 
 
    [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; 
 
} 

请您参考如下方法:

你需要在多线程概念中做一些工作(比如卸载)。我认为 This是一个非常好的教程,准确地提到了你的问题(也解决了它:)我希望它有所帮助

编辑:Apple says you can go on downloading in the background.

Background Tasks



继续网络传输是显而易见的

application of background tasks. If the user starts a large transfer and then switches out of your app, it can start a background task to continue the transfer. If all goes well the transfer will be finished before the user next brings the app to the front. When implementing background task support in your app, it's not necessary for you to have separate logic for the "in the background" and "in the foreground" cases.


标签:大数据
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号