1

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.

shle2821
  • 1,856
  • 1
  • 19
  • 26
  • 1
    You can include up to three key names in the `desiredKeys` property https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CKNotificationInfo_class/#//apple_ref/occ/instp/CKNotificationInfo/desiredKeys but the size of data is limited. Generally you will need to use the notification to trigger a fetch if the data you need – Paulw11 Mar 19 '16 at 20:17
  • Thank you! It was very helpful – shle2821 Mar 19 '16 at 23:15

1 Answers1

2

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

Lars Christoffersen
  • 1,719
  • 13
  • 24