Send Push Notifications using Amazon SNS service

2019-07-15 11:08发布

问题:

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.

As far as I understood:

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

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)

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?

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

回答1:

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

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.

You might end up having:

  1. "Apple-staging" with APNS-Sandbox
  2. "Apple-production" with APNS

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

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. User says yes to P.N.
  2. Your server receives the token that the phone got from APNS, GMS, etc.
  3. Your server in turn, using Amazon's sdk, will create the endpoint.
  4. That's it.

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.

Error handling

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.