Using Amazon SNS with React Native

amazon-sns, ios, node-modules, push-notification, react-native

Solution

There's no 'integration' of AWS into the RN app needed. You just need the device token from RN.

Use a package like RNPN (https://github.com/zo0r/react-native-push-notification) in order to get the device token your phone generates. When you have that, make a call to your api, and your api is then responsible to call out to SNS to register that device token as an SNS 'endpoint'.

Translate this pseudo-code into whatever your API is written in: https://docs.aws.amazon.com/sns/latest/dg/mobile-platform-endpoint.html

In short...

- RNPN onRegister ->

- POST /registerDevice on your api ->

- call AWS createPlatformEndpoint from your api ->

- start sending messages from your api

Most likely you'll want to store some relationship from user -> deviceToken+platformEndpoint in your db/data store.

Then you can send notifications from your api. Wrote up how to do that here: https://medium.com/@duhseekoh/send-a-push-notification-using-aws-sns-javascript-sdk-2f117e9c4180

Problem

Can anyone provide a simple example of using the Amazon SNS service to send and receive Push Notifications under React Native? I've got the Amazon SNS service setup, and I can publish a message from the website and have it appear on an iPhone – if I manually enter the device token and initiate the publish on the Amazon website. Now I want to automate the process of registering the Push Token in Amazon SNS, and allow the app to Publish a push to the SNS service. I know that Amazon has a very new project to integrate their SDK into React Native, but I cannot get it working. Support on that repo is spare too, so I'm hoping someone here can help. Right now what I get is: `Undefined is not an object (evaluating 'cognateClient.initWithOptions')` The GitHub issues mention something similar on Android, but obviously that doesn't help with my iOS app. What I'm looking for is a step-by-step breakdown of how to integrate Amazon's code in to an existing RN app. They don't provide a standard Node package, so I'm struggling to figure out how to get the React Native code and the SDK to play nice with Xcode. Any suggestions? Thanks!

Original source