在iOS4的后台继续长时间运行的过程

我有一个使用ASIHTTP请求运行的上传队列。 当用户按主屏幕和应用程序进入后台,我希望这个操作继续。 从文档中我可以看到我将如何调用一个新的任务可以调用在后台运行,但不能完全看到我将如何标记已经运行的任务继续。

这个例子是括号内的4.0前兼容性:

UIApplication *app = [UIApplication sharedApplication]; if ([app respondsToSelector:@selector(beginBackgroundTaskWithExpirationHandler:)]) { backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ dispatch_async(dispatch_get_main_queue(), ^{ if (backgroundTaskIdentifier != UIBackgroundTaskInvalid) { // you took too long - clean up what you can, then … [app endBackgroundTask:backgroundTaskIdentifier]; backgroundTaskIdentifier = UIBackgroundTaskInvalid; } }); }]; } // start HTTP request … 

当你完成你的过程时,你应该调用endBackgroundTask:让应用程序知道