我想上传一些应该继续下去的文件,即使应用程序进入后台。NSOperation和NSOperationQueue的后台任务iOS
目前我正在从数据库中检索文件,并通过NSOperation将其添加到队列中,然后启动上载过程。
即使应用程序转到后台或前台,也应该上传所有文件。 下面是单个任务的代码,任何人都可以给我一个提示,我们如何使它可以上传许多文件。
UIApplication* application = [UIApplication sharedApplication];
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
[application endBackgroundTask: bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
我不认为这个答案是正确的。 'waitUntilAllOperationsAreFinished'调用应该在'beginBackgroundTaskWithExpirationHandler'之后进行,而不是在expiration块内。看到这个答案:http://stackoverflow.com/questions/10319643/objective-c-proper-use-of-beginbackgroundtaskwithexpirationhandler – Dima 2014-12-08 22:32:01