java - 没有收到来自 firebase 的推送通知但是使用 Pusher 应用程序

标签 java ios swift firebase firebase-cloud-messaging

我没有收到来自 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 _ 在 app delegate 中将 notificationCenter delegate 设置为 self

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

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

   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_ 我在 Capabilities 中启用了推送通知

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

一些提示:

我们是一个像服务器端(JAVA)一样的团队。 web , android 和 ios

此推送通知在 android 上有效,但在 ios 上无效。

我想我做错了。

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

最佳答案

以下是交叉检查问题的步骤,

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

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

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

在 header 中,添加您的服务器 key (您可以从您的 firebase 控制台获取)

enter image description here

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

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

enter image description here

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

enter image description here

关于java - 没有收到来自 firebase 的推送通知但是使用 Pusher 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54633523/

相关文章:

swift - 是否有任何提交催化剂应用程序的指南?

java - 确定数字是否为 'insipid' 的方法

ios - 通过 URL 在 CollectionView 中显示图像时出现问题

java - 以编程方式构建 Netbeans 平台应用程序时出现 Ant 类路径错误

iphone - 如何修复 ‘NSObjectInaccessibleException’ 获取请求在被 NSManagedObjectContext 使用之前无法响应 -entity'

iphone - 我可以使用 Objective-C block 并仍然在 iOS 4 之前的设备上运行吗?

ios - UITableView 中的删除按钮(SWIFT)

swift - 快速从一个类访问另一个类的变量

java - java中的十进制格式

java - 使用空赋值来控​​制监听器的添加和删除