FCM与AWS SNS [英] FCM with AWS SNS

本文介绍了FCM与AWS SNS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的android项目使用 AWS 资源,我打算使用 AWS SNS 。有几个问题困扰我很多。我没有发现任何有关这些问题的问题,除了一两个问题,但解释不清楚。

1.是 AWS 支持 FCM SNS 使用 GCM 。但Google建议使用FCM而不是 GCM 。我没有找到 AWS 支持 FCM



2 .Do AWS 将消息(或数据)存储到数据库中,甚至在发送推送通知之后?

3.我试过将FCM API密钥放入SNS应用程序平台中,它显示无效参数为什么?

在AWS上设置FCM的步骤与 GCM建立程序,并且(至少目前为止)FCM与GCM和SNS在服务器端配置方面透明地工作。



然而, ,如果您要将 data 有效载荷发送至Android设备,则除非您实施客户端服务,它扩展了 FirebaseMessagingService 。 AWS控制台中的默认JSON消息生成器会发送 data 消息,除非实现上述服务,否则这些消息将被您的应用忽略。为了解决这个问题,你可以提供一个定制的通知有效载荷,这个有效载荷将会被你的设备接收(只要你的应用程序不在前台)



GCM-FCM迁移说明由Google提供,但您需要进行的更改主要在应用程序方面。



您需要遵循以下步骤在您的应用程序上使用SNS测试GCM / FCM:


  1. 创建 SNS平台应用程序,选择Google云消息传递(GCM)作为推送通知平台,并提供您的服务器API密钥

  2. 选择平台应用程序并单击创建平台端点按钮。

  3. 提供您的应用生成的InstanceID(设备令牌)。您必须扩展 FirebaseInstanceIDService 并覆盖 onTokenRefresh 方法才能在您的Android应用程序中查看此内容。 完成此操作后,请卸载并重新安装您的应用程序,并且您的令牌应在首次启动时打印到Android Studio中的调试控制台。

  4. 单击添加终端节点按钮。

  5. 点击适用于平台应用程序的ARN链接。

  6. 为您的设备选择新创建的端点,然后点击发布至端点按钮。

  7. 选择JSON 消息格式,然后点击 JSON消息生成器按钮。 >输入测试消息并单击生成JSON 按钮

  8. 现在出现gotcha部分。

由SNS生成的消息将采用以下格式:

  {
GCM:{\data \:{\message \:\test message \}}
}

如前所述,如果没有服务, data 有效载荷将被忽略接收他们已经实施。我们想测试而不写太多的代码,所以我们应该发送一个通知有效载荷。要做到这一点,只需将JSON消息更改为:

  {
GCM:{\通知\:{\text \:\test message \}}
}

完成此操作后,请确保您的应用未在设备上运行,然后点击发布消息按钮。您现在应该会看到在您的设备上弹出通知。



当然,您可以通过Amazon SNS API以编程方式完成所有这些操作,但所有示例似乎都使用 data 有效载荷,因此您需要牢记这一点,并生成适合您的用例的有效负载。


I am using AWS resources for my android project, I am planning to add push notification service for my project with AWS SNS.there are few questions bothering me much. I did not find any questions regarding these, except one or two but with unclear explanations.

1.Does AWS support FCM? SNS work with GCM. But Google recommends to use FCM instead of GCM. I did not find AWS supporting FCM.

2.Do AWS store messages (or data) into their databases even after sending push notifications?

3.I tried putting FCM api key in SNS application platform, it is showing invalid parameters why?

解决方案

FCM is backwards compatible with GCM. The steps for setting up FCM on AWS are identical to the GCM set up procedure and (at least for the moment) FCM works transparently with GCM and SNS with respect to server-side configuration.

However, if you are sending data payloads to the Android device they will not be processed unless you implement a client side service that extends FirebaseMessagingService. The default JSON message generator in the AWS console sends data messages, which will be ignored by your app unless the aforementioned service is implemented. To get around this for initial testing you can provide a custom notification payload which will be received by your device (as long as your app is not in the foreground)

There are GCM-FCM migration instructions provided by Google however the changes you need to make are predominantly on the App side.

The steps you need to follow to test GCM/FCM on your app with SNS are:

  1. Create a Platform Application in SNS, selecting Google Cloud Messaging (GCM) as the Push Notification Platform, and providing your Server API key in the API key field.
  2. Select the Platform Application and click the Create platform endpoint button.
  3. Provide the InstanceID (Device Token) generated by your app. You must extend the FirebaseInstanceIDService and Override the onTokenRefresh method to see this within your Android App. Once you have done this, un-install and re-install your app and your token should be printed to the Debug console in Android Studio on first boot.
  4. Click the Add endpoint button.
  5. Click on the ARN link for your platform application.
  6. Select the newly created Endpoint for your device and click the Publish to endpoint button.
  7. Select the JSON Message Format, and click the JSON message generator button.
  8. Enter a test message and click the Generate JSON button
  9. Now comes the "gotcha part".

The message that is generated by SNS Will be of the form:

{
"GCM": "{ \"data\": { \"message\": \"test message\" } }"
}

As we mentioned earlier, data payloads will be ignored if no service to receive them has been implemented. We would like to test without writing too much code, so instead we should send a notification payload. To do this, simply change the JSON message to read:

{
"GCM": "{ \"notification\": { \"text\": \"test message\" } }"
}

Once you have done this, make sure your app is not running on the device, and hit the Publish Message button. You should now see a notification pop up on your device.

You can of course do all this programatically through the Amazon SNS API, however all the examples seem to use the data payload so you need to keep that in mind and generate a payload appropriate to your use case.

这篇关于FCM与AWS SNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆