Search code examples
cloudkitcksubscription

Is it a way to get notification with CKSubscription that a user started to use app?


I need to know when a user started using app. I know I can set up CKSubscription for arbitrary record type, but it seems that for Users it does not work.

CKSubscription(recordType: "Users", predicate: NSPredicate(value: true), options: .FiresOnRecordCreation | .FiresOnRecordUpdate | .FiresOnRecordDeletion)

Solution

  • Users is a special recordType. As you can see in the CloudKit dashboard it also has a separate item in the menu. You won't be able to access it from the Public Data Default Zone. The easiest way around this is to create a recordType of your own when the app starts up. For instance you could make a UserSettings recordType. Then you can create a subscription for that. You do have to be aware that then everybody will receive notifications for every new user. Of course you don't want to handle thousands of notifications per day? :)