Reputation: 326
I'm trying to setup subscriptions for CloudKit Records, the subscription creates OK, I can retrieve it with CKFetchSubscriptionsOperation
successfully. But the function
application(_:didReceiveRemoteNotification:)
doesn't get called...
(I'm changing the records by hand in Dashboard)
The subscription is setted in this way:
let database = CKContainer.default().privateCloudDatabase
let subscription = CKSubscription(recordType: "Device", predicate: NSPredicate(format: "TRUEPREDICATE"), options: .firesOnRecordUpdate)
let notificationInfo = CKNotificationInfo()
notificationInfo.alertLocalizationKey = "DEVICE_UPDATED"
notificationInfo.alertBody = "Device updated in database"
subscription.notificationInfo = notificationInfo
database.save(subscription) { subscription, error in
if error != nil {
print(error?.localizedDescription as Any)
} else {
print(subscription)
}
}
And Registration registration for Notification is:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let notificationSettings = UIUserNotificationSettings(types: [.alert, .badge], categories: nil)
application.registerUserNotificationSettings(notificationSettings)
application.registerForRemoteNotifications()
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
print(userInfo)
}
Upvotes: 2
Views: 579
Reputation: 326
Ok, I had to enable push notifications and generate "Apple Push Notification service SSL Certificate" and attach it to my app at Apple Developer Provisioning Profiles page
Upvotes: 2