Search code examples
iosswiftapple-push-notificationscloudkitcksubscription

How to send multiple columns of information using CKSubscription


I can get CKSubscription work using CKNotificationInfo() and CKNotificationInfo.alertBody. So I can send one piece of information. I'm trying to make CKSubscription send the user something like message, username, location, etc in a dictionary format. I've dabbled with CKNotificationInfo.alertLocaliztionKey and CKNotificationInfo.alertLocaliztionArgs but just can't seem to make it work. It feels like i'm missing something small because CKSubscription shouldn't be this troublesome to make it work.


Solution

  • Because that is not what is intended in the notification framework. What you do get back is information about WHAT has changed, and then you have to fetch this data and do what ever you want to do. I have made an app which both tells the user that something has changed and silently in the back refreshes the local data:

    let cloudKitNotifiction = CKQueryNotification(fromRemoteNotificationDictionary: uif)
            if cloudKitNotifiction.notificationType == CKNotificationType.Query{
                if let recordId = cloudKitNotifiction.recordID{
                    let ccs = CloudCoreSynchronizer()
                    ccs.syncOneCustomerFromCloudToCore(recordId)
                    resetBadgeCounter()
                }
            }
    

    To make this work you have to enable push notifications and background modes, if you want it to happen when the app is in the background.Hope this helps. PS: Just disregard the inapp purchase thing, it has nothing to do with this

    enter image description here