我在ios的app中使用了Firebase Cloud Messaging Notification,但是在真机测试时,发现收不到任何推送消息。
我使用 iOS 的 firebase 统一包。 我检查了所有步骤,但我不知道问题出在哪里。
我使用 p8 APNs 文件,钥匙串(keychain)中的开发人员身份和推送通知。
在xcode中,我打开选项(推送通知和后台模式),但它无法接收推送消息,后台或前台。
xcode控制台的登录是这样的:
[Firebase/Messaging][I-FCM002010] The subscription operation is suspended because you don't have a token. The operation will resume once you get an FCM token.
[GULReachability][I-REA902004] Network status has changed. Code:2, status:Connected
FCM: Initialize Firebase Messaging
FCM: Initialize Firebase Messaging
FCM: Retrieve registration token
FCM: Retrieve registration token
RequestPermissionAsync completed
[Firebase/InstanceID][I-IID003012] Provisioning profile has specifically provisioned devices, most likely a Dev profile.
[Firebase/InstanceID][I-IID003013] APNS Environment in profile: development
最佳答案
The subscription operation is suspended because you don't have a token. The operation will resume once you get an FCM token.
您需要注册您的 iOS 客户端的 FCM token 。
Firebase 有非常详细的设置文档:Setting Up a Firebase Cloud Messaging Client App on iOS
它的核心来自于在您的 AppDelegate
中包含这段代码:
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
然后您需要处理给定的 token 。您应该将此 token 存储在您的 Firebase 数据库中,然后您需要在发送推送通知时包含它。
Firebase 有一个发送推送通知的示例,其中包括用于存储这些 token 的数据库结构,位于此处:Send Firebase Cloud Messaging notifications for new followers .
关于ios - 在 ios 中未收到 Firebase 云消息传递通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52118227/