Ich versuche, Daten zwischen einigen Apple TVs mit CloudKit und CKSubcription zu synchronisieren. Das Problem ist application:didReceiveRemoteNotification:
wird nie aufgerufen, wenn ich Datensätze hinzufügen, löschen oder aktualisieren. Ich glaube, ich konfiguriere die Abonnements korrekt und ich habe bestätigt, dass sie dem CloudKit-Dashboard hinzugefügt werden. Ich habe wiederholt versucht, die Entwicklungsumgebung im Dashboard zurückzusetzen, aber das hilft nicht. Ich möchte wirklich keinen Timer erstellen, der so oft abzurufen ist. Danke für jede Hilfe!CloudKit Abonnements in tvOS
Ich verwende auch die private Datenbank in CloudKit und nicht die öffentliche Datenbank, wenn das wichtig ist.
Hier ist mein Code:
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)
}
}
}
Ich benutze 'Anwendung: didReceiveRemoteNotification' und nicht' Anwendung: didReceiveRemoteNotification: fetchCompletionHandler'. Ich habe EVCloudKitDao angeschaut und es sieht so aus, als ob Sie bei jedem Start der App alle Abonnements löschen und neu abonnieren. Ich mache das nicht, ist das möglicherweise das Problem? Ist es nötig? Macht es einen Unterschied, da ich die private Datenbank und nicht die öffentliche Datenbank in CloudKit verwende? Vielen Dank –