【发布时间】:2017-02-11 02:53:43
【问题描述】:
为了让推送通知在 iOS10 中工作,我抓狂了。当前设置:
在func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool:
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if error == nil {
print("DID REQUEST THE NOTIFICATION")
UIApplication.shared.registerForRemoteNotifications()
}
}
print("DID SET DELEGATE")
}
在func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data):
print("DID REGISTER FOR A REMOTE NOTIFICATION AND THE TOKEN IS \(deviceToken.base64EncodedString())"
let request = UpdatePushNotificationSubscription_Request(deviceToken: deviceToken)
updatePushNotificationSubscriptionWorker.updateSubscription(request)
我已检查令牌是否正确上传到后端,并且确实匹配。
我也实现了:
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("GOT A NOTIFICATION")
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
//This is for the user tapping on the notification
print("GOT A NOTIFICATION")
}
我已为所有目标设置了权利并启用了推送:
现在,当我尝试从后端发送消息时,设备什么也没有收到。没有召集代表。不知道我在这里做错了什么。 Push 适用于 iOS9 和 android 设备。任何指向我可能做错了什么的指针?
【问题讨论】:
-
这不是一个真正的答案,因为我仍然和你有同样的问题。尝试检查您的设备令牌是否被正确解析,因为对我来说,截至 ios10,它不是。但是我确实修复了它,但我仍然没有调用我的代表
-
您找到解决方案了吗?
-
有人对此有解决方案吗?自 iOS 10 以来,我也遇到了同样的问题 - 现在在 iOS 10.1.1
-
您的问题解决了吗?即使我面对
-
我认为问题在于您没有在
userNotificationCenter方法中调用completionHandler。只需添加并测试。
标签: ios swift apple-push-notifications