我正在開發一個應用程序,並且在用戶退出應用程序時遇到問題。 假設該應用程序正在下載3張圖片。 用戶退出應用程序。 如何繼續下載(因爲我們正在談論剩下的2個月,而不是500個!)? 我知道是這樣的:iOS - 如何在應用程序進入後臺之前完成任務
if ([_downloader isDownloading]) {
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you.
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"dispatch_async debut");
// Do the work associated with the task, preferably in chunks.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
NSLog(@"dispatch_async fin");
});
}
的問題是,我的任務已經在處理。我不想重新開始下載!
你有什麼想法嗎?
非常感謝您的回答。
謝謝@stavash,但我不想爲此使用外部庫/類 – Dabrut 2012-03-05 15:13:25