简体   繁体   English

查明 FCM 推送通知状态“成功”但未在控制台/设备中收到

[英]Pinpoint FCM push notification status “Successful” but not received in console/device

I've got an android app and I'm trying to send push notifications to it through Amazon Pinpoint.我有一个 android 应用程序,我正在尝试通过 Amazon Pinpoint 向它发送推送通知。

  • My App is able to receive FCM push notifications sent via Postman with my API key.我的应用程序能够使用我的 API 密钥接收通过 Postman 发送的 FCM 推送通知。
  • These notifications appear both on the FCM Console, and on the device.这些通知同时出现在 FCM 控制台和设备上。

Then I set up FCM push notifications in pinpoint with the same API key, and tested with their "Test Messaging" tool.然后我使用相同的 API 密钥精确设置 FCM 推送通知,并使用他们的“测试消息”工具进行测试。 在此处输入图像描述

  • Test message tool says message was sent succesfully.测试消息工具说消息发送成功。
  • message does NOT appear on device or in FCM console.消息不会出现在设备或 FCM 控制台中。
  • I get a similar success response using the pinpoint CLI, or sending it through my RAILS app.我使用 pinpoint CLI 或通过我的 RAILS 应用程序发送了类似的成功响应。
  • APNS messages are working end-to-end with pinpoint for my application. APNS 消息在我的应用程序中与 pinpoint 端到端工作。

I get a Success response for FCM messages sent through the test messaging tool, through the CLI and send from my Rails application, but none of them appear in the FCM console, or arrive at the device.对于通过测试消息传递工具、通过 CLI 并从我的 Rails 应用程序发送的 FCM 消息,我收到了成功响应,但它们都没有出现在 FCM 控制台中,也没有到达设备。

The only thing I have noticed in the setup that doesn't match the documentation is Pinpoint doesn't seem to have anywhere to add a Sender ID , just the API Key.我在设置中唯一注意到与文档不匹配的是 Pinpoint 似乎没有任何地方可以添加Sender ID ,只有 API 密钥。 (However, I'm not sure the sender ID is actually necessary since I can send a POST request directly with just the API key and FCM gets it... maybe this is outdated?? ) (但是,我不确定发件人 ID 是否真的必要,因为我可以只使用 API 密钥直接发送 POST 请求并且 FCM 得到它......也许这已经过时了??)

If for some reason the Sender ID is actually required, where would it be entered?如果由于某种原因实际上需要发件人 ID,它将在哪里输入?

What else can I do to debug this?我还能做些什么来调试这个? 在此处输入图像描述

"My App is able to receive FCM push notifications sent via Postman with my API key & These notifications appear both on the FCM Console, and on the device" “我的应用程序能够使用我的 API 密钥接收通过 Postman 发送的 FCM 推送通知,这些通知同时出现在 FCM 控制台和设备上”

From the above quote, since when testing with FCM ( Firebase Cloud Messaging ) directly you receive the push notification on your device then I suspect that the issue could be related to either two things ie PushListener class or push notification message type.从上面的引述中,由于在使用 FCM ( Firebase Cloud Messaging ) 直接测试时,您会在设备上收到推送通知,那么我怀疑该问题可能与两件事有关,即 PushListener class 或推送通知消息类型。 Let me explain :让我解释一下

When it comes to FCM Push Notifications, there are two types of message types that are supported ie either “Data” or ”Notification” .对于 FCM 推送通知,支持两种类型的消息类型,即“数据”“通知” So by default FCM console/SDK sends push notification of type "Notification" message.因此,默认情况下,FCM 控制台/SDK 会发送“通知”消息类型的推送通知。 This type of message is handled by FCM SDK automatically and delivered to the notification tray of the app.此类消息由 FCM SDK 自动处理并传送到应用程序的通知托盘。 While on the other hand, “Data" messages are not handled the FCM SDKs and the clients' need to handle this type of messages.另一方面,FCM SDK 不处理“数据”消息,客户端需要处理此类消息。

Amazon Pinpoint, currently by default uses “Data” message type for standard message which means that, the Client app has to implement methods' (eg implementing a PushListenerClass that ingests the payload and displays the incoming notification in the notification tray ) to process the payload and take action. Amazon Pinpoint,目前默认情况下使用“数据”消息类型作为标准消息,这意味着客户端应用程序必须实现方法(例如,实现一个 PushListenerClass 提取负载并在通知托盘中显示传入通知)来处理负载并采取行动。

Can you confirm whether in your application code you have a PushListener Class?您能否确认您的应用程序代码中是否有 PushListener Class? If not, then you can refer to the following articles which explains in details how to handle FCM Messages (Notification and Data) in Android:如果没有,那么您可以参考以下文章,其中详细解释了如何在 Android 中处理 FCM 消息(通知和数据):

https://www.zoftino.com/android-notification-data-messages-from-app-server-using-firebase-cloud-messaging https://www.zoftino.com/android-notification-data-messages-from-app-server-using-firebase-cloud-messaging

https://aws-amplify.github.io/docs/android/push-notifications https://aws-amplify.github.io/docs/android/push-notifications

If you want to send push notification of type "Notification" then you'll need to use:如果要发送“通知”类型的推送通知,则需要使用:

  1. RawContent property if using Pinpoint SDK/REST API/CLI.The RawContent property needs to be defined/specified as a JSON-formatted string as illustrated below: RawContent属性(如果使用 Pinpoint SDK/REST API/CLI)。 RawContent 属性需要定义/指定为 JSON 格式的字符串,如下所示:

     'RawContent': '{"notification":{"title":"TEST PUSH NOTIFICATION","body":"Hello, this is a test push notification,"}}', // If you define 'RawContent' here. everything ("message") else in the "MessageConfiguration" will be ignored.
  2. RawMessage property if using Pinpoint console as illustrated below where you substitute "data" with "notification": RawMessage 属性,如果使用 Pinpoint 控制台,如下图所示,您将“数据”替换为“通知”:

在此处输入图像描述

Hope that helps,,希望有帮助,,

The standard message is data message by default when it's sent to firebase.标准报文发送到 firebase 时默认为数据报文。 To send a notification, you need to send it as raw message.要发送通知,您需要将其作为原始消息发送。 here's an example for both APNs and Firebase这是 APN 和 Firebase 的示例

  "APNSMessage": {
    "aps": {
      "alert": {
        "title": "Hello Apple",
        "subtitle": "Notification test",
        "body": "From Pinpoint"
      }
    }
  },
  "GCMMessage": {
    "notification": {
      "title": "Hello Android",
      "body": "From PinPoint"
    }
  },
  "ADMMessage": {
    "data": {
      "message": ""
    }
  },
  "BaiduMessage": {
    "title": "",
    "description": ""
  }
}```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM