Technical Q&A QA1917

Debugging issues with CloudKit subscriptions

Q:  My CloudKit subscriptions don’t trigger notifications after relevant changes are made. How to debug that?

A: Most CloudKit subscription issues are either due to incorrect assumptions about when and where notifications should fire or improperly configured CloudKit containers or subscriptions. This document will introduce you some cases that aren't expected to trigger CloudKit notifications, following with how to verify the state of your iCloud container and how to avoid some common issues related to CloudKit subscriptions.

Cases that aren't expected to trigger CloudKit notifications

When working with CloudKit subscriptions, be aware that:

With these cases in mind, if your issue is still there, the next step is to verify the state of your iCloud container.

Verify the state of your iCloud container

You can verify the state of your iCloud container with the following steps:

  1. Prepare two iOS devices running the latest iOS, log in iCloud with the same Apple ID, and make sure iCloud Drive is On. You can use an iOS Simulator to change the CloudKit database, but only a device can register and receive push notifications. CloudKit works on macOS and tvOS as well, so you can set up Macs or Apple TVs similarly if you are using a macOS or tvOS app for this verification.

  2. Download Apple's CloudKit Catalog sample, change the bundle ID to the one being used in your app, pick the right iCloud container in Xcode’s Capabilities pane if you use a custom one, then build and run the sample on your devices. Make sure notification settings are allowed, as discussed above.

  3. Create a query subscription to track record creations. On one device, run the CloudKit Catalog sample, go to Subscriptions > saveSubscription screen, set the subscriptionType to Query, input something in the name BEGINSWITH field that will be used in the subscription predicate, then tap the Run Code button.

  4. One the other device, go to Records > saveRecord screen and add a new record, make sure the record name begins with the string you just input so that it matches the subscription predicate, then tap the Run Code button.

Your first device should soon get a notification, proving that your iCloud container is functioning. If this does not work, it is likely that your iCloud container is in an invalid state. In that case, you can report it by filing a bug report, and continue your development using a new iCloud container and / or logging in iCloud with a new Apple ID.

To use a new iCloud container, go to the Xcode's Capabilities panel, switch the iCloud > Containers options to Specify custom containers, then pick or add a new container. To create a new Apple ID, follow the steps on the Create Your Apple ID page.

With the same iCloud container and Apple ID, if CloudKit Catalog works well but your app doesn’t, the next step is to check if your app has any coding issue related to CloudKit subscriptions.

Avoid common issues related to CloudKit subscriptions

The following issues are frequently seen when working with CloudKit subscriptions:



Document Revision History


DateNotes
2016-11-16

New document that explains how to debug the issue that CloudKit subscriptions don't trigger notifications when the relevant changes are made.