swiftcloudkitcksubscription

CKSubscription returns error that query must have at least one firing mode when using FiresOnce


I have this code. Which works when creating a subscription with a firing mode of FiresOnRecordCreation... but getting error on FiresOnce.. the error is "Query Subscriptions must have at least one type of firing mode"

My goal is that I have a photo. When the first rating of the photo occurs i want to get a notification. I do not want to use FiresOnRecordCreation on the reference as for every rating there will be a notification which is too many. I just want the first notification for the first rating received.

    let database = CKContainer.defaultContainer().publicCloudDatabase
    let predicate = NSPredicate(format:"owningPhoto == %@", ref)
    let subscription = CKSubscription(recordType: "PhotoRatings", predicate: predicate, options: .FiresOnce)

xcode crashes on the subscription but on with FiresOnce.


Solution

  • besides the .FireOnce you should also indicate if that's for creation, update or deletion. So the call should be something like:

       let subscription = CKSubscription(recordType: "PhotoRatings", predicate: predicate, options: [.FiresOnce, .FiresOnRecordCreation, .FiresOnRecordUpdate, .FiresOnRecordDeletion])