1

我没有从 firebase 收到任何通知,但是当我使用 Pusher 应用程序进行测试时,我收到了通知。

这些是我已经完成的步骤。如果我做错了什么,请帮助我。

1_添加如下通知服务。

class NotificationService: UNNotificationServiceExtension {

var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
    self.contentHandler = contentHandler
    bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

    if let bestAttemptContent = bestAttemptContent {
        // Modify the notification content here...




        bestAttemptContent.title = "hello"
        bestAttemptContent.body = "this is test"


        contentHandler(bestAttemptContent)
    }
}

}

2 _ 在应用程序委托中将 notificationCenter 委托设置为 self

        Messaging.messaging().delegate=self
        UNUserNotificationCenter.current().delegate = self

3_ 用于发送通知的设备令牌(我将其存储到服务器)

   func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
    print("Firebase registration token: \(fcmToken)")

    let dataDict:[String: String] = ["token": fcmToken]
    NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
    // TODO: If necessary send token to application server.
    // Note: This callback is fired at each app startup and whenever a new token is generated.
}

我将此 FCMToken 发送到服务器端(java,spring boot)

4_ 我在功能中启用了推送通知

5_ 我在 Firebase 控制台的项目设置的云消息传递中添加了 .p12 文件,但我对此有很大的疑问!????我应该使用我的服务器帐户登录到 firebase 吗?或者为我自己做一个帐户??因为我为自己创造了一个。

一些技巧 :

我们是一个像服务器端(JAVA)这样的团队。网页、安卓和ios

此推送通知适用于 android 但不适用于 ios。

我想我在做错事。

感谢您阅读本主题并帮助我。

4

1 回答 1

2

这是交叉检查您的问题的步骤,

  1. 必须启用通知功能。
  2. 您在苹果会员中心创建的证书应该启用推送通知 在此处输入图像描述
  3. 在 Firebase 控制台中转到设置 -> 项目设置 -> 云消息传递 -> 检查服务器密钥
    1. 这个密钥和你给服务器团队的密钥应该是一样的
    2. 检查是否添加了 APNs 身份验证密钥或 APNs 证书。
    3. 如果您使用的是 APNs 证书,则应该与您在会员中心的 appId 中生成的证书相同 在此处输入图像描述
  4. 从 xcode 控制台获取 fcm 令牌 -> 转到 firebase 控制台 -> 增长 -> 云消息传递 -> 新通知 -> 并尝试在设备上进行测试。如果您收到通知客户端(设备)没有问题。如果不是服务器端必须仔细检查服务器密钥。
  5. 将您的 googleServiceInfo.plist 添加到您的项目中。在您的应用信息中添加反向密钥。
  6. Appdelegate,配置你的火力基地 FirebaseApp.configure()

更新,根据您在评论中的问题,我正在更新这个问题。要使用 NotificationService 扩展,您的通知必须mutable-content在通知负载中包含属性。使用 fcm api 你可以做到这一点。把这些放在邮递员那里,

https://fcm.googleapis.com/fcm/send

在标题中,添加您的服务器密钥(您可以从您的 firebase 控制台获取)

在此处输入图像描述

在正文中添加此有效负载以触发通知。这将触发您的通知服务扩展。

{
    "notification": {
        "title": "1",
        "body": "",
        "click_action": "",
        "icon": "",
        "mutable_content": true,
        "content_available": true
    },
    "registration_ids":["add your fcm token"],
    "data": {}
}

在此处输入图像描述

根据教程: https ://code.tutsplus.com/tutorials/ios-10-notification-service-extensions--cms-27550

在此处输入图像描述

于 2019-02-11T16:20:13.567 回答