我想上傳一些應該繼續下去的文件,即使應用程序進入後臺。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