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

标签 iphone ios ipad ios4

我正在一个单独的 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.

关于iphone - 在多任务模式下下载大数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9212400/

相关文章:

iphone - 如何更改UInavigationBar附带的工具栏的颜色/样式?

ios - Html 字符串转换为属性字符串\U00002028\n ios

iphone - 计算 iPhone 上的像素大小

ios - swift : Process UIImage data for use in Firebase custom TFLite model

swift - 如何使用 SwiftUI 呈现小页面?

iphone - Xcode,只检索带有字母 A 的地址簿姓氏(依此类推)

iphone - 需要有关 iPhone 上的动画的帮助

iphone - 如何在 iPhone 中隐藏导航栏?

android - 使用 PhoneGap Build 的 BackgroundFetch/后台运行应用程序

ios - 我的应用程序现在在尝试实现 RevMob 后抛出错误