使用Amazon SNS服务发送推送通知

问题描述:

我们正在开发一种发送推式通知的移动应用程序,我们想使用Amazon SNS服务来实现它,我想确认一下我们计划如何管理设备注册和推式通知发送的总体思路.

we are developing a mobile application which sends push notifications and we would like to do it using Amazon SNS service and I would like to confirm the general idea of how we are planning to manage devices registration and push notifications sending.

据我了解:

在Amazon SNS中,存在PlatformApplication的概念,我们在其中指定它是Android/iPhone还是环境(Test/Prod,...)

In Amazon SNS there is the concept of PlatformApplication where we specify if it's Android/iPhone et also the environment (Test/Prod,...)

然后,存在用于设备和移动应用程序"的PlatformEndPoint的概念,因此,我想对于每个下载并安装了该应用程序的人,有必要根据设备的类型在适当的平台中创建一个EndPoint. (Android,苹果)

Then, there is the concept of PlatformEndPoint "for a device and mobile app" so, I imagine that for each person who has downloaded and installed the application it's necessary to create an EndPoint in the appropiate platform depending on the kind of device (android,apple)

我的问题是,何时应创建此PlatformEndPoint,此人每次登录到应用程序时,我们每次注销时都应将其删除?

My question is ,, when this PlatformEndPoint should be created, each time the person logs in into the application and we should remove it each time he logouts?

然后,在创建PlatformEndPoint之后,我需要向特定用户(而不是向所有人)发送推送通知,我将对适当的TargetArn参数使用Publish API.

Then when the PlatformEndPoint is created and I need to send push notification to a specific user (not to everybody) I will use Publish API with the appropiate TargetArn param.

非常感谢您的评论和建议

Thanks a lot for your comments and suggestions

首先,您需要手动通过SNS仪表板(或使用SDK).

First of all you need to create the applications endpoints by hand through the SNS dashboard (or using the SDK).

在这里您可以为Apple声明一个测试环境(APNS-Sandbox).其他环境没有专门的测试环境. (即Google),但是即使您使用相同的消息传递提供程序,也鼓励您创建测试和生产应用程序.

Here is where you could declare a testing environment for Apple (APNS-Sandbox). Other environments don't have specialized testing envs. (i.e Google), but you're encouraged to create testing and production applications, even though they will use the same Messaging Provider.

您可能最终拥有:

  1. 使用APNS-Sandbox的"Apple-staging"
  2. 使用APNS的"Apple生产"

注意:您可以针对特定设备类型优化端点. "iPhone登台"和/或"iPad登台"等.

Note: you can refine your endpoints for specific device type. "iPhone-staging" and/or "iPad-staging" etc.

第二: 一旦有了应用程序端点,就需要在系统中具有代码,该代码知道根据系统环境命中哪个端点.即开发和登台可能指向"Apple登台"端点.生产可能指向苹果生产".

Second: Once you have the application endpoints, you need to have code in your system that knows which endpoint to hit according to the system's environment. i.e development and staging might point to "Apple-staging" endpoint. Production could point to "Apple-production".

第三: 每当用户接受推式通知对话框时,都必须创建用户的端点,该端点又与应用程序端点相关.

Third: Whenever a user accepts the push notifications dialog, you must create the user's endpoint which in turn is related with the application endpoint.

  1. 用户对P.N说是".
  2. 您的服务器从APNS,GMS等接收电话获得的令牌.
  3. 您的服务器将依次使用Amazon的sdk创建端点.
  4. 就是这样.

最后 当您要发送推送通知时,您需要获取用户的arn(或终端节点)并使用Amazon sdk中的publish方法.

Last When you want to send a push notification, you'll need to grab the user's arn (or endpoint) and use the publish method in the Amazon sdk.

错误处理

如果未成功发送推送通知,则用户的端点将自动禁用.您需要决定如何处理它们,以便将来进行通知.您可以利用Amazon SQS来解决问题,并且错误处理的实现可能会有所不同.

User's endpoints get disabled automatically if the push notification wasn't sent successfully. You need to decide what to do with them for future notifications. You could leverage Amazon SQS for that matter and implementations of error handling could vary.