Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Amazon SNS with React Native

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!

like image 438
Axeva Avatar asked May 26 '26 03:05

Axeva


2 Answers

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

like image 145
duhseekoh Avatar answered May 27 '26 16:05

duhseekoh


Im using react-native-fcm with Amazon sns, it will register my device token and then we are sending that token to our php solution that then add the device to a subscription on a topic in SNS, passed back to the app is the subscription token and endsub tokens. Then we Push Messages to the topic thru SNS. Works on both iOS and Android.

like image 27
Palm Avatar answered May 27 '26 17:05

Palm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!