I'm trying to create a subscription for CloudKit Notifications but I can't seem to get the predicate right. Simple notifications, with just a one comparison predicate show up, so the payload is configured correctly, but If I make the predicate a little more complex it doesn't receive any notifications. I need to subscribe to multiple record changes but I have to do it one by one. What I want is to be able to just have one subscription using IN or OR but it doesn't seem to work.
working predicate
let predicate = NSPredicate(format: "recordID == %@", recordID1)
non-working predicates
let recordIDs = [recordID1, recordID2, recordID3, recordID4]
let predicate1 = NSPredicate(format: "recordID IN %@", recordIDs)
let predicate2 = NSPredicate(format: "NOT recordID IN %@", recordIDs)
var predicate3 = NSPredicate(format: "recordID != %@", recordID1)
for id in recordIDs.filter {$0 != recordID1} {
predicate3 = NSCompoundPredicate(andPredicateWith: [predicate, NSPredicate(format: "recordID != %@", id)])
}
I'm using for reference the CKQuery CloudKit guide (https://developer.apple.com/reference/cloudkit/ckquery). Is the subscriptions predicate implementation different or am I just creating wrong predicates? By the way, all predicates compile, on breakpoints they show up correctly, there are no errors in the code, the app doesn't crash at any point, I have verified that the subscriptions are in fact on the server and with the predicates I've specified. It doesn't matter if the record is changed on a device or on the server, more complex predicates never seem to match any.
For the sake of completion, here is the rest of the subscription code that works perfectly using the first predicate but not the rest,
let subscription = CKSubscription(recordType: "Avatar", predicate: predicate, options: CKSubscriptionOptions.FiresOnRecordUpdate)
let notificationInfo = CKNotificationInfo()
notificationInfo.shouldSendContentAvailable = true
subscription.notificationInfo = notificationInfo
Any help is greatly appreciated.