【发布时间】:2015-04-20 07:34:24
【问题描述】:
我正在使用 UIBackgroundtaskIdentifier 创建将图像上传到服务器的后台任务。
NSLog(@"Time left = %.1f seconds", [UIApplication sharedApplication].backgroundTimeRemaining);
当我将应用程序置于后台时,它显示应用程序有 179 秒的时间在后台运行。我在服务器一张一张上传图片时记录服务器响应。
[[DataCoordinator sharedInstance] setBackgroundTask:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"No background task should run now.");
[[UIApplication sharedApplication] endBackgroundTask:[[DataCoordinator sharedInstance] backgroundTask]];
[[DataCoordinator sharedInstance] setBackgroundTask:UIBackgroundTaskInvalid];
}]];
这里发生的奇怪事情是,在 iOS 为我的应用程序在后台运行提供的时间结束后,上传仍然没有停止。假设我尝试上传 33 张图片,当 179 秒完成申请时,成功上传了 33 张图片中的 9 张。但这个过程并没有停止。并且应用程序不断上传剩余的图片。
【问题讨论】:
标签: ios objective-c cocoa-touch uikit uibackgroundtask