Well I finally got the CloudKit notification working after much effort.
Perhaps my ignorance in dealing with the result is the problem but
it seems to be a very cumbersome approach.
One issue is when I create a record on the iPhone, the OS X app gets
the expected .firesOnRecordCreation option. But when I delete the record, I get the
'or' of .firesOnRecordCreation and .firesOnRecordUpdate (the value 3)
I present all 3 options when I create the subscription
let qSubscription = CKQuerySubscription(recordType: "Student", predicate: predicate, subscriptionID: "test",
options: [.firesOnRecordCreation,.firesOnRecordUpdate, .firesOnRecordDeletion])
I also set shouldSendMutableContent to true in the notificationInfo object
however I don't get the record fields, I just get the record ID. What mutable
content am I supposed to get?
The other issue is how cumbersome the code appears. Is this really the way to use the userInfo object that is returned?
Seems like there must be a more elegant way.
Any tips would be appreciated. Thanks!
Here's the code (On the OS X app).
func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
guard let ck = userInfo["ck"] as? [String: AnyObject] else {
return
}
guard let qry = ck["qry"] as? [String: AnyObject] else {
return
}
let recordID = qry["rid"] as! String
print(recordID)
let options = CKQuerySubscription.Options( rawValue: qry["fo"] as! UInt )
switch options {
case .firesOnRecordCreation:
print("FIRE ON RECORD CREATION")
break
case .firesOnRecordDeletion:
print("FIRE ON RECORD DELETE")
break
case .firesOnRecordUpdate:
print("FIRE ON UPDATE")
break
default:
print("DEFAULT \(options)")
}
}