2017-07-29 53 views
1

我在我的應用程序中使用了CloudKit。從iCloud檢索所有更改我使用操作CKFetchRecordZoneChangesOperation。當我沒有活動的互聯網連接時添加此操作時,fetchRecordZoneChangesCompletionBlock永遠不會被調用。IOS:fetchRecordZoneChangesCompletionBlock在沒有互聯網連接時不會調用

我的確希望這個完成塊被調用時發生錯誤CKError.networkUnavailable。

我正在使用swift 3.

我可能誤解了一些東西。有人可以解釋我缺少的東西嗎?

回答

1

CKOperation Documentation

CKOperation對象有 NSQualityOfServiceUtility服務水平的默認質量。此 級別的操作被視爲可自行決定,並由系統 根據電池級別和其他因素安排最佳時間。在 iPhone上,低功耗模式爲 啓用時,任意活動暫停。

你需要做的是手動設置CKFetchRecordZoneChangesOperation的服務質量,以.userInitiated

// userInitiated: Used for performing work that has been explicitly requested by the user, 
// and for which results must be immediately presented in order to allow for further user interaction. 
// For example, loading an email after a user has selected it in a message list. 
// 
// set to userInitiated make sure the completion with error will immediately returned if currently no internet connection 
zoneOperation.qualityOfService = .userInitiated 
+0

感謝什麼!這解決了我的問題。 – Leontien

相關問題