Enable push notifications for React Native apps includes configuring the backend, configuring your app and processing notifications in your code with the Push Notification API.
Configuring the backend with Mobile Hub
Push notifications are generated by push notification services such as the Apple Push Notification (APN) service 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 notifications to any mobile device, without trading in your app with SDKs from multiple vendors.
Follow these steps to enable push notifications in your app:
- Register your app with the platform push notification system (APN & # 39; s, FCM or ADM). Keep the registration keys and credentials for use in the following steps.
- Add & # 39; Messaging and Analytics & # 39; to your project in Mobile Hub.
- Update the push notification credentials for the related reporting services in Mobile Hub.
- Mobile Hub automatically takes care of the AWS resources your app needs. An Amazon Pinpoint project is created and integrated into the back-end of your app.
You can later create campaigns for mobile push notifications in the Amazon Pinpoint console. See the Amazon Pinpoint User Guide for more information on working with Amazon Pinpoint campaigns.
Configuring your native Native app
To receive and process notifications on mobile devices, you must also configure your application. For iOS and Android the required configuration parameters are different. Follow the installation instructions for notifications in the AWS Amplify notification installation guide.
Tests and tracking notifications
After building your React Native app with the required configuration, you are ready to send and receive notifications in your app. With the Amazon Pinpoint console you can create push message campaigns, where you can send messages directly or plan for later.
When you receive notifications in your app, AWS Amplify offers two handlers that you can deploy and use to add custom behavior. The following code sample displays the payload of the notification on an Android device.
PushNotification.onNotification (data => ); PushNotification.onRegister (data => );