ios - FCM 通知未收到 iOS
<p><p>我正在使用 FCM 获取远程推送通知。</p>
<p>因此,在从以下回调中获取第一个 FCMtoken 时,我能够触发通知并正确接收它们。</p>
<pre><code>func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String)
</code></pre>
<p>重新启动应用程序后,我得到了一个新的 FCMtoken 。新 token 不会触发任何通知。</p>
<p>根据文档,我遵循的先决条件:
<a href="https://firebase.google.com/docs/cloud-messaging/ios/client" rel="noreferrer noopener nofollow">https://firebase.google.com/docs/cloud-messaging/ios/client</a> </p>
<p><strong>使用 FirebaseMessaging (3.3.0)</strong></p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>所以我找到了解决方案,每次从回调中获取 FCM 新 token 后。</p>
<pre><code>func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String)
</code></pre>
<p>我们必须重新注册远程推送通知。</p>
<pre><code>if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.badge, .alert, .sound]) {
(granted, error) in
if granted {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
//print("APNS Registration failed")
//print("Error: \(String(describing: error?.localizedDescription))")
}
}
} else {
let type: UIUserNotificationType =
let setting = UIUserNotificationSettings(types: type, categories: nil)
UIApplication.shared.registerUserNotificationSettings(setting)
UIApplication.shared.registerForRemoteNotifications()
}
</code></pre>
<p>FirebaseMessaging 将使用设备 token 重新配置新的 FCMtoken 。</p>
<p><strong>注意:</strong>不可以,需要明确设置设备 token 。由于 FirebaseMessaging 使用的是方法调配,它会自动从委托(delegate)方法中检索它。</p>
<pre><code>func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
</code></pre></p>
<p style="font-size: 20px;">关于ios - FCM 通知未收到 iOS,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/55374328/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/55374328/
</a>
</p>
页:
[1]