Search code examples
iosswiftpush-notificationcloudkitcksubscription

CloudKit subscription not working in production


Using a CKSubscription from CloudKit to listen for updates and changes on the database and receiving silent notifications works fine on Development but once in Production it doesn't work at all.

Trying to save a CKSubscription on a CKDatabase using save(_:completionHandler:) throws the error:

<CKError 0x600001eab3f0: "Invalid Arguments" (12/2006); server message = "attempting to create a subscription in a production container"; op = F4A51E76AB7CBA90; uuid = FF807DA3-0BAC-4B99-A653-E26EE35DC95F; container ID = "iCloud.my.cool.app.42">

On the CloudKit Dashboard (the web interface) logs the subscriptions are working fine on development but on production they have the error: BAD_REQUEST for the log type: subscription modify.

Right on the documentation it says:

Note

Create subscriptions in the development environment first and then promote them to production. Attempting to create a subscription directly in the production environment results in an error.

So first I need to create it on development and then promote it for production, ok, but how?

I couldn't find much clarification on the documentation, but reading some useful posts and blogs, including this one from Filip Němeček, they point out that this is done on the CloudKit Dashboard.

The process should be quite simple:

  1. Create a CKSubscription on development (using just the simulator works fine).
  2. Go to CloudKit Dashboard > Database > Container (your app) > Environment: Development > Data > Subscriptions > Database (public, private or shared).
  3. Newly create subscription should be on the list.
  4. Deploy Schema Changes... (deploy to production just as deploying any other schema change).
  5. New subscription is ready for production.

The problem is that point 3 doesn't work for me, there is no new subscription appearing under Subscriptions on the Dashboard.

How can I promote the subscription to production?


Solution

  • Reading more comments on forums folks mention you can only see subscriptions on CloudKit dashboard created by the active account logged on the dashboard, I'm using a Sandbox Account for testing.

    There is a button on CloudKit Dashboard to help with this: Act As iCloud Account…. But the functionality is very limited once you activate it. Also this was not an alternative for me.

    I found out that if you create a CKSubscription on the development environment (and it succeeds, without throwing errors) this will be ready for promoting, even if you can't see it on the dashboard.

    1. Create the subscription on development
    2. Go to CloudKit Dashboard
    3. Deploy Schema Changes…
    4. Even if it seems there is nothing to deploy, still deploy it
    5. Subscription must be ready for Production environment