0
我正嘗試使用CloudKit和CKSubcription在幾臺Apple TV之間同步數據。問題是我添加,刪除或更新記錄時從不會調用application:didReceiveRemoteNotification:
。我相信我正確配置訂閱,並且我確認他們已添加到CloudKit儀表板。我曾多次嘗試重置儀表板中的開發環境,但這並沒有幫助。我真的不想創建一個定時器來經常抓取每一個。謝謝你的幫助!tvOS中的CloudKit訂閱
此外,我正在使用CloudKit中的私有數據庫,而不是公用數據庫,如果這很重要。
這裏是我的代碼:
AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
CloudKitManager.subscribeToItemUpdates()
application.registerForRemoteNotifications()
...
return true
}
CloudKitManager.swift
class func subscribeToItemUpdates() {
if let uuid = UIDevice.currentDevice().identifierForVendor?.UUIDString {
saveSubscriptionWithIdentifier(uuid + "create", options: CKSubscriptionOptions.FiresOnRecordCreation)
saveSubscriptionWithIdentifier(uuid + "update", options: CKSubscriptionOptions.FiresOnRecordUpdate)
saveSubscriptionWithIdentifier(uuid + "delete", options: CKSubscriptionOptions.FiresOnRecordDeletion)
}
}
class func saveSubscriptionWithIdentifier(identifier: String, options: CKSubscriptionOptions) {
let sub = CKSubscription(recordType: "Message", predicate: NSPredicate(value: true), subscriptionID: identifier, options: options)
sub.notificationInfo = CKNotificationInfo()
let publicDatabase = CKContainer.defaultContainer().publicCloudDatabase
publicDatabase.saveSubscription(sub) { (savedSubscription, error) -> Void in
if error != nil {
print("Error saving CloudKit subscription \(error)")
}
else {
print("Saved subscription to CloudKit", savedSubscription)
}
}
}
我使用'應用:didReceiveRemoteNotification'而不是'應用:didReceiveRemoteNotification:fetchCompletionHandler'。我查看了EVCloudKitDao,看起來您正在刪除所有訂閱,並在每次啓動應用程序時重新訂閱。我不這樣做,這可能是問題嗎?有必要嗎?因爲我在使用私有數據庫而不是CloudKit中的公共數據庫,所以它有什麼不同嗎?謝謝 –