Search code examples
iosswiftcloudkitcksubscription

Encountering CKSubscription error: "Cannot create or modify field 'notif_num_subtitle_loc_args'"


So I’m running into a CloudKit error that only gets a single (1) Google result when I search for it. I get the error when running a CKModifySubscriptionsOperation to create an initial user’s CK subscription. The error is Cannot create or modify field 'notif_num_subtitle_loc_args'

I am pretty sure this used to work, so it's possible this came in with iOS 10.3 or something internal in CloudKit?

Here is the code I use for creating the subscription:

    let subscriptionID = "MindscopeDownload"
    let predicate = NSPredicate(format: "TRUEPREDICATE")
    let options: CKSubscriptionOptions = [.firesOnRecordCreation, .firesOnRecordUpdate, .firesOnRecordDeletion]
    let subscription = CKSubscription(recordType: "MindscopeNode", predicate: predicate, subscriptionID: subscriptionID, options: options)
    let info = CKNotificationInfo()
    info.alertLocalizationKey = "Mindscope entry changes"
    info.shouldSendContentAvailable = true
    subscription.notificationInfo = info
    let op = CKModifySubscriptionsOperation(subscriptionsToSave: [subscription], subscriptionIDsToDelete: [])
    op.modifySubscriptionsCompletionBlock = { (foo, bar, error: Error?) -> () in
        if let e = error {
            print("Failed to modify subscription: \(e)

Here is the Google result of someone having the same problem: https://forums.developer.apple.com/thread/76893


Solution

  • I'm having exactly the same problem, it appeared sometime between April 1 and April 17, while I was out of the office (and thus not making any code changes). I opened a bug, which has been closed as a dup. The original bug remains open. So at least Apple acknowledges this is a bug.

    I only see this error in the production environment, and I found two work arounds:

    1. Create a new container, create the subscription types in the dev env, deploy to production. Creating new subs in the new container in prod worked again.

    Unfortunately, this left me with an empty container, and I wasn't eager to write migration code to move data from the orig container to the new container.

    1. In the original container, in the dev environment, delete all subscription types using the dashboard. Recreate them in the app, then push the changes to production. Creation of subs in the original container in prod worked again.

    Unfortunately, this wiped out all existing subs created by all users for the deleted subscription types. Fortunately for me, the list of subscriptions per user is static in my app. My code already validated/recreated missing subs at startup. But, if your users dynamically chose stuff to subscribe to, this will be a painful situation to manage. (you can fetch the existing subs and cache the predicates before wiping the subscription types, but that will require coordinating with your users to ensure they've all cached their existing subs in time)

    Note that I also tried simply creating new subs with new subscription IDs with the same predicates. That failed outright, complaining that the new subs were duplicates of existing sub types. If there are additional clauses you can add to your predicate, you may be able to create new sub types that work when deployed to prod.