So I'm trying to create a new subscription based on a predicate. The predicate is if there is a new Record (of type Message) with conversationID to a given conversation ID.
Okay so I've enabled notifications on my device and subscriptions do get sent to CloudKit. But then when I go onto the CloudKit dashboard I get this response:
Error fetching subscriptions.
Expected this response but could not parse it: HTTP 200, text: [{"subscriptions":[{"type":"query","subscriptionId":"CDF6D9BD-77E5-41C6-BC18-3AD1A49E1A7D","query":{"recordType":"Message","filters":{"fieldName":"conversationID","fieldValue":{"type":"stringType","value":"C8356727-83A0-4981-9C62-48B891B376EB"},"type":"EQUALS"}]},"firesOn":["CREATE"],"firesOnce":false,"zone":{"zoneName":"_zoneWide","canonicalName":"_zoneWide","ownerRecordName":"_df807ec5aa88995e336922b90835b528"}}]}
So I'm confused about this.
It seems like that is the response I was looking for, and I'm not sure why it can't query it. I remember seeing in another question something about there being an issue with a listEmpty or something.
But I'm querying on a string so I don't understand why it's not working.
my CloudKit code looks like this:
func setNotifications(convoID: String) {
let database = CKContainer.default().publicCloudDatabase
let pred = NSPredicate(format: "conversationID == %@", convoID)
let newSubscription = CKQuerySubscription(recordType: RecordType.Message, predicate: pred, options: [.firesOnRecordCreation])
let notification = CKSubscription.NotificationInfo()
notification.alertBody = "You have a new message"
notification.shouldSendContentAvailable = true
newSubscription.notificationInfo = notification
database.save(newSubscription) { (subscription, error) in
if let error = error {
print(error)
return
}
if let _ = subscription {
print("Hurrah! We have a subscription")
}
}
}
Thanks!