gpt4 book ai didi

ios - 未收到来自 CloudKit 订阅的推送通知

转载 作者:搜寻专家 更新时间:2023-10-31 21:48:46 25 4
gpt4 key购买 nike

我没有收到来自 CloudKit 订阅的推送通知。

这是我到目前为止所做的:

  • 启用了 CloudKit 和远程通知功能。
  • 使用 CloudKit 仪表板创建了“测试”记录类型。
  • 为适当的记录类型(测试)创建了一个订阅,它我可以在 CloudKit 仪表板中看到。
  • 使用物理设备进行测试,该设备已登录到 iCloud 并且连接到互联网。
  • 设置应用代理以接收通知。
  • 通过 CloudKit 门户手动插入/更新/删除记录。

不幸的是,我从未收到过任何推送通知。涉及的代码如下所示。从字面上看,这是一个全新的空白项目中的唯一代码。

    // MARK: - SUBSCRIPTIONS
func subscribeToRecordChangesWithRecordType (recordType:String, database:CKDatabase) {

let predicate = NSPredicate(value: true)
let subscription = CKSubscription(recordType: recordType, predicate: predicate, options: CKSubscriptionOptions.FiresOnRecordCreation|CKSubscriptionOptions.FiresOnRecordDeletion|CKSubscriptionOptions.FiresOnRecordUpdate)

database.saveSubscription(subscription, completionHandler: { (savedSubscription, error) -> Void in
if let _error = error {
NSLog("ERROR saving '%@' subscription %@",recordType, _error)
} else {
NSLog("SUCCESS creating '%@' subscription: %@", recordType, savedSubscription)
}
})
}
func createSubscriptions () {
let privateDB = CKContainer.defaultContainer().privateCloudDatabase
let publicDB = CKContainer.defaultContainer().publicCloudDatabase


// NOTE: create a Record Type called 'Test' in the CloudKit dashboard
self.subscribeToRecordChangesWithRecordType("Test", database: privateDB)
self.subscribeToRecordChangesWithRecordType("Test", database: publicDB)
}

// MARK: - PUSH NOTIFICATIONS
func registerForPushNotifications (application: UIApplication) {
self.createSubscriptions()
let settings = UIUserNotificationSettings(forTypes: .Alert, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
NSLog("Registered for Push Notifications with token: %@", deviceToken);
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
NSLog("FAILED to register for Push Notifications. %@", error)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
NSLog("RECEIVED Push Notification")
NSNotificationCenter.defaultCenter().postNotificationName("PushNotificationReceived", object: userInfo)
}
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
NSLog("RECEIVED LOCAL Push Notification")
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

NSLog("RECEIVED Push Notification with fetchCompletionHandler")
NSNotificationCenter.defaultCenter().postNotificationName("PushNotificationReceived", object: userInfo)
}

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

self.registerForPushNotifications(application)
return true
}

提前感谢任何提示或建议。我希望这不是一个错误,我在这里做错了什么......它应该“正常工作”!

干杯

最佳答案

确定

  1. 您已在应用程序的“功能”选项卡中启用除 CloudKit 之外的推送通知(如果需要,还启用后台模式)。如果需要,从 Developer Portal 找到推送证书(一个用于开发,一个用于生产),下载并安装它们(通过双击它们);

  2. 您正在设备上测试应用。 Apple 不会推送到模拟器。

关于ios - 未收到来自 CloudKit 订阅的推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29008794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com