簡體   English   中英

NSOperation隊列在后台不起作用

[英]NSOperation queue not working in background

我希望圖像上傳可以在后台運行 我啟用了“ 后台模式”,並創建了一個“ 操作”隊列以一次將多個文件上傳到服務器。 但是,一旦將應用程序置於后台,NSOperation就會暫停,並在前台運行時再次重新啟動。 我還添加了beginBackgroundTaskWithExpirationHandler以便在將所有圖像上傳到服務器時啟動我的操作隊列和endBackgroundTask之前。

這樣一來,當應用程序處於后台狀態時,所有圖像也都上傳到服務器,但是我的應用程序被殺死了,我不希望該應用程序被殺死。

請為我的問題提出一些解決方案。

您的應用在后台運行時的時間有限。 在分配的時間到期后,它將被殺死。

根據蘋果的說法:

In your own expiration handlers, you can include additional code needed
to close out your task. However, any code you include must not take too 
long to execute because, by the time your expiration handler is called,
your app is already very close to its time limit. For this reason,
perform only minimal cleanup of your state information and end the
task.

還獲取backgroundTimeRemaining屬性的值以檢查剩余時間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM