Using Amazon SNS with React Native

Can someone provide a simple example of using Amazon SNS to send and receive push notifications in the React Native section?

I have an Amazon SNS service setup, and I can post a message from the website and show it on the iPhone - if I manually enter the device token and initiate the publication on the Amazon website. Now I want to automate the process of push token registration in Amazon SNS and allow the application to publish push for SNS.

I know that Amazon has a very new project to integrate its SDK into React Native, but I cannot get it to work. Support on this repo is also worth it, so I hope someone here can help.

Now I get: Undefined is not an object (evaluating 'cognateClient.initWithOptions')

The GitHub release mentions something similar on Android, but obviously this doesn't help in my iOS app.

What I'm looking for is a step-by-step breakdown of how to integrate Amazon code into an existing RN application. They don't provide a standard Node package, so I'm struggling to figure out how to get React Native code and the SDK to play well with Xcode.

Any suggestions? Thanks!

+6
source share
2 answers

Im using action-native-fcm with Amazon sns, it will register my device token, and then we will send this token to our php solution, which will then add the device to the topic subscription in SNS, the subscription tokens and endubs are transferred back to the application . Then we send messages to the topic via SNS. It works on both iOS and Android.

0
source

There is no β€œintegration" of AWS into the RN application. You just need the device token from RN.

Use a package such as RNPN ( https://github.com/zo0r/react-native-push-notification ) to get the token of the device that your phone generates. When you have it, make a call to your api, and then your api will be responsible for calling SNS to register this device token as an SNS endpoint.

Translate this pseudo-code into everything your API is written for: 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 will want to save some relationships from the user β†’ deviceToken + platformEndpoint in your db / data repository.

Then you can send notifications from your api. Wrote how to do this: https://labnotes.panderalabs.com/send-a-push-notification-using-aws-sns-javascript-sdk-2f117e9c4180

0
source

Source: https://habr.com/ru/post/1011635/


All Articles