ios - 在 ios 中未收到 Firebase 云消息传递通知

标签 ios firebase unity-game-engine firebase-cloud-messaging

我在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/

相关文章:

ios - 如何将 UIActivityIndi​​cator 插入搜索栏文本字段?

ios - 带有手势的 Scrollview 内的图像

firebase - Google Cloud Platform - 将 "no organization"的 firebase 项目移动到 "organization"时出错

android - 如何在项目单击时从 FirebaseListAdapter 获取 obj 键。 Firebase用户界面

unity-game-engine - 如何使用Unity在ARcore增强图像场景中显示不同图像的不同预制件?

javascript - 类型错误 : undefined is not an object only in Safari and iOS

objective-c - 跨不同平台管理 iOS 应用程序

c# - Unity AdMob 广告未显示

swift - 为 UIKitForMac 构建 iPad 应用时出现构建错误

ios - 如何将网格的每个顶点绘制为圆