當主頁按鈕按下並且應用程序在背景中時,我想上傳圖像。 這可能嗎?如果是,那麼如何?如果沒有,那麼我有其他的選擇嗎? 在此先感謝...當應用程序進入後臺時可以調用webRequest嗎?
1
A
回答
3
您可以在後臺通過使用此代碼爲特定的時間
UIBackgroundTaskIdentifier bgTask = 0;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
self.silenceTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self
selector:@selector(startLocationServices) userInfo:nil repeats:YES];
我認爲這將幫助ü。 :)
+0
謝謝....我通過閱讀蘋果文檔得出結論:上傳過程可以在應用程序轉到背景後執行最長10分鐘, – 2013-03-07 09:46:55
+0
歡迎您@KhushbuPatel ..快樂編碼:) – shivam 2013-03-07 10:29:56
1
應用程序可以請求在關閉後最多10分鐘後在後臺運行,以便它可以完成長時間運行的任務。只有一些進程被允許在後臺運行。見實現長時間運行的後臺任務部分in this reference.
如果您的應用允許的話,你可以試試下面的代碼:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIBackgroundTaskIdentifier bgTask;
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), ^{
// Do the work associated with the task, preferably in chunks.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
,如果你想知道你的程序還剩多少時間來運行
NSTimeInterval ti = [[UIApplication sharedApplication]backgroundTimeRemaining];
NSLog(@"Remaining Time: %f", ti); // just for debug
更多裁判去與這個reference PDF(page 60)
相關問題
- 1. 當應用程序進入後臺並進入前臺時調用UIViewController方法
- 2. 當應用程序進入後臺時運行後臺線程
- 3. 當應用程序進入後臺時,應用程序代理不會調用
- 4. Swift - 當應用程序進入後臺時進入視圖
- 5. 我可以知道應用程序進入後臺時按了哪個鍵嗎?
- 6. 當應用程序進入後臺時使計時器無效
- 7. 當Android應用程序從後臺進入前臺時如何獲取回調?
- 8. 可以調用performSelectorOnMainThread:調用beginBackgroundTaskWithExpirationHandler並且應用程序在後臺之後嗎?
- 9. Android應用程序進入後臺時能檢測到嗎?
- 10. 當我的應用程序進入後臺時,可以將一個循環放入dispatch_async嗎?
- 11. 當應用程序進入後臺時取消API請求
- 12. 當應用程序進入後臺時顯示暫停菜單
- 13. 當應用程序進入後臺時運行MPMoviePlayer
- 14. 當應用程序進入後臺時關閉彈出窗口
- 15. 當應用程序進入後臺時,startAdvertisingPeer是否工作?
- 16. 當應用程序進入後臺時處理事件
- 17. 當應用程序進入後臺模式時釋放圖形
- 18. 當應用程序剛進入後臺時顯示提醒
- 19. UIDeviceBatteryLevelDidChangeNotification當應用程序進入後臺時的問題
- 20. 當應用程序進入後臺時執行Segue
- 21. 當應用程序進入後臺時啓動JavaScript函數
- 22. 當應用程序進入後臺時繼續下載
- 23. 當應用程序進入後臺時關閉modalviewcontroller
- 24. 當從後臺調用應用程序時調用方法
- 25. 應用程序在後臺運行時可以截屏嗎?
- 26. Android - 應用程序的LeScanCallback會在應用程序進入暫停(到後臺)時被調用嗎?
- 27. Facebook應用程序進入前臺後
- 28. 當應用程序在後臺時NSURLConnection
- 29. 當應用程序在後臺時使用iBeacon進行廣告
- 30. OnDestroy()當應用程序轉到後臺時被調用服務
http://developer.apple.com/library/ios/#technotes /tn2277/_index.html – Desdenova 2013-03-07 09:19:29