我正在写一个同步数据的iOS应用程序。我需要同步服务才能在应用处于后台时运行。所以我在我上传数据的地方写了这段代码。IOS - 在后台执行有限长任务
- (void)startAsyncUpload {
UIApplication *thisApplication = [UIApplication sharedApplication];
if([thisApplication respondsToSelector:@selector(beginBackgroundTaskWithExpirationHandler:)]) {
bgTaskIdentifier_ = [thisApplication beginBackgroundTaskWithExpirationHandler:^(void)
{
[thisApplication endBackgroundTask:bgTaskIdentifier_];
bgTaskIdentifier_ = UIBackgroundTaskInvalid;
}];
}
[self multipartUpload];}
它工作正常,并在后台运行。但我在这里遇到问题。我正在上传一个视频文件,当我的背景时间到期时,处理程序被调用并结束了任务。现在,当我再次上传到上传时,没问题。但是现在当我再次背景时,它不会恢复后台任务。
我知道为什么,基本上是因为我之前完成了任务。但是有没有什么办法可以再次恢复任务,例如为了后台运行再次注册任务?
你可以使用线程来实现它我想这样... – 08442 2013-04-23 09:37:18
如何,你能解释一下吗? – Advaith 2013-04-23 10:11:14