AWS Amplify adds support for push notifications in React Native and provides new features for user authentication | Amazon Web Services

March 05, 2018 0 Comments

AWS Amplify adds support for push notifications in React Native and provides new features for user authentication | Amazon Web Services



AWS Amplify is a declarative JavaScript library for working with cloud services. It has built-in support for creating React Native applications. For push notifications in React Native, AWS Amplify introduces an easy-to-use client API and backend configuration over AWS Mobile Hub. The latest version of  the AWS Amplify JavaScript library has been enhanced to support push notifications in React Native and includes improvements for user authentication.

Enabling push notifications for React Native apps involves configuring the backend, configuring your app, and handling notification messages in your code with the Push Notification API.

Configuring the backend with Mobile Hub

Push notifications are generated by push notification services like the Apple Push Notification service (APNs) for iOS, Firebase Cloud Messaging (FCM) for Android, and Amazon Device Messaging (ADM) for Amazon devices. You can use AWS Mobile Hub and Amazon Pinpoint to orchestrate those services and send push messages to any mobile device, without dealing with multiple vendor SDKs in your app.

To enable push messaging in your app, follow these steps:

  • Register your app with the platform push notification system (APNs, FCM, or ADM). Keep the registration keys and credentials for use in the next steps.
  • Add ‘Messaging and Analytics’ to your project in Mobile Hub.
  • Update the push notification credentials for the related notification services in Mobile Hub.
  • Mobile Hub automatically provisions the AWS resources that your app requires. An Amazon Pinpoint project is created and integrated into your app backend.

You can later create campaigns for mobile push notifications in the Amazon Pinpoint console. For more information about working with Amazon Pinpoint campaigns, see the Amazon Pinpoint User Guide.

Configuring your React Native app

In order to receive and handle notifications on mobile devices, you need to configure your application as well. For iOS and Android, the required configuration parameters are different. Follow the setup instructions for notifications in the AWS Amplify notifications setup guide.

Testing and tracking notifications

After building your React Native app with the required configuration, you’re ready to send and receive notifications in your app. The Amazon Pinpoint console enables you to create push messaging campaigns, where you can send messages directly or schedule them for later.

When receiving notifications in your app, AWS Amplify provides two handlers that you can implement and use to add custom behavior. The following code sample displays the notification payload on an Android device.

PushNotification.onNotification(data => { alert('Notification payload', data); }); PushNotification.onRegister(data => { alert('in app registration', data); });

Tag cloud