Search code examples
iosicloudcloudkit

Can CloudKit subscriptions not be created in code?


I've got 'dynamic' subscriptions that I need to create when the app runs and these cannot be pre-determined as they're based on some unique ID I generate temporarily for each device connecting. When running in development mode, CloudKit works perfectly however in Distribution mode I keep getting this error:

<CKError 0x1358436e0: "Invalid Arguments" (12/2006); server message = "attempting to create a subscription in a production container"; uuid = 41F4CA23-9849-40B1-8DB5-0030BBD91251; container ID = "iCloud.com.company.CloudKit">

Is there no way to create a subscription dynamically? I thought only RecordTypes needed to be created using the Dashboard.


Solution

  • The solution turned out to be something else. I was previously using the saveSubscription method of the private database. This apparently kept giving me the above mentioned error. I ended up using CKFetchSubscriptionsOperation and CKModifySubscriptionsOperation and this now works perfectly.

    In my case I did have the subscription types setup in Production and also had everything else setup correctly. It was just the matter of using the above mentioned operations instead and that seems to have done the trick.