Search code examples
databaseauthenticationpush-notificationswiftuicloudkit

Cloudkit PushNotifications not veing delivered, but subscription created in Schema


I followed the Hacking With Swift guide to set up push notification and they just weren't appearing on my phone. I set up a new public zone I called Notifications and was using a CKQuerySubscription (since the other doesn't work on private databases). The Query was created in schema, but nothing was being created in the Data>Subscriptions. I was saving the data successfully to the Zone, and creating the subscription twice would show the error "failed duplicate subscription exists" so I knew that was working. I also followed all the advice on the cococast site post called "Five Reasons CloudKit Notifications Are Not Arriving", and I was using a real device not a physical one. Still no notifications.


Solution

  • The reason the push notifications weren't coming to my device was because I was using only 1 iphone. You can't send a push notification that "a new record was created" to the device that made the record. As soon as I switched over to using the simulator to make the Record, my physical device started getting the push notifications. Both simulator and physical device were signed into the same icloud account.

    So the process looks like:

    1. App installed on physical device (Signed into iCloud). Subscribe to zone changes in physical device.
    2. Launch the app on the simulator (Signed into iCloud).
    3. Save a record on the simulator
    4. Push Notification will appear on the physical device.