iOS 未收到来自 CloudKit 的推送通知
Posted
技术标签:
【中文标题】iOS 未收到来自 CloudKit 的推送通知【英文标题】:iOS Not receiving Push Notification from CloudKit 【发布时间】:2017-01-27 20:24:37 【问题描述】:我正在尝试为 CloudKit Records 设置订阅,订阅创建成功,我可以使用 CKFetchSubscriptionsOperation
成功检索它。但是函数
application(_:didReceiveRemoteNotification:)
没有被调用...
(我在 Dashboard 中手动更改记录)
订阅是这样设置的:
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)
Notification的注册注册为:
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)
【问题讨论】:
您是在真机还是模拟器上运行您的应用程序? 是的,我都试过了 通知在模拟器上不起作用,但真机应该没问题。尝试在您的应用委托中实现application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
。你接到func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
的电话了吗?
连真机都不行,所以不知道自己做错了什么,按照这个教程,还是不行——m.youtube.com/watch?v=BXl5o5_2aEU
我没有在这两个函数中被调用,我启用了后台模式 -> 远程通知,但我想一般来说注册远程通知存在问题
【参考方案1】:
好的,我必须在 Apple Developer Provisioning Profiles 页面启用推送通知并生成“Apple Push Notification service SSL Certificate”并将其附加到我的应用程序
【讨论】:
真的吗?是这样吗? 其实应该没关系以上是关于iOS 未收到来自 CloudKit 的推送通知的主要内容,如果未能解决你的问题,请参考以下文章