Topics

Topics

CloudKit lives on the client. You write Swift or Objective-C code to interact with Apple's iCloud servers to save and retrieve data. But what if your app wants to support push notifications? Don’t worry CloudKit has you covered. Use CKSubscription to tell CloudKit you'd like to know when records matching a predicate are created, updated, or deleted. CloudKit will deliver a special push notification to your app denoting the change, which you can customize for your needs.

Let's take a look at setting it up: (don't forget to setup and register for push notifications!)

Then when you receive the push notification use it's userInfo to create a CKNotification object and grab the ID of the new record:

letnotification:CKNotification=CKNotification(fromRemoteNotificationDictionary:userInfo)ifnotification.notificationType==CKNotificationType.Query{letqueryNotif=notificationas!CKQueryNotification// do something interesting with queryNotif.recordID}