Page updated Nov 14, 2023

Migrate from previous version

If you were previously using the now deprecated version of Amplify Push Notifications for React Native (@aws-amplify/pushnotification), you will need to migrate to the new version by following the steps outlined here.

Update your configuration

  1. Make sure you are using the latest version of the Amplify CLI.
1amplify upgrade
  1. Pull your project (even if there are no changes) to update your configuration.
1amplify pull

Replace your dependency

  1. Remove the old dependency from your project.
1npm uninstall @aws-amplify/pushnotification

Please note that it's recommended to delete your yarn.lock file, package-lock.json file as well as the /node_modules folder before adding the new native module.

  1. Add the new native module to your project.
1npm install @aws-amplify/rtn-push-notification

Update build configurations

Update your Podfile

Amplify Push Notifications now requires a minimum target of iOS 13.0.

  1. Open Podfile located inside the /ios folder of your React Native project with a text editor.

  2. Update platform :ios to at least 13.0.

1platform :ios, '13.0'
  1. Install the new pods by running the following command at the root of your React Native project.
1npx pod-install

Update your Application Delegate

  1. Reverse the steps previously taken to augment your AppDelegate

  2. Locate and open your AppDelegate.m or AppDelegate.mm file in your text editor. You should find it in your React Native project under /ios/<your-project-name>

  3. At the top of your AppDelegate, import Amplify Push Notifications:

1#import "AppDelegate.h"
2#import "AmplifyPushNotification.h"
3
4...
  1. In the body of your AppDelegate, add the following two methods:
1- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
2 [AmplifyPushNotification didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
3}
4
5- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
6 [AmplifyPushNotification didReceiveRemoteNotification:userInfo withCompletionHandler:completionHandler];
7}

Update gradle scripts

Amplify Push Notifications now requires a minimum target of Android SDK API level 24.

  1. Open build.gradle located inside the /android folder of your React Native project with a text editor.

  2. Update the minSdkVersion value in the buildscript block to at least 24.

1buildscript {
2 ext {
3 ...
4 minSdkVersion = 24
5 ...
6 }
7}
  1. Open the application build.gradle located inside the /android/app folder of your React Native project with a text editor.

  2. Remove firebase dependencies from the dependencies block.

1dependencies {
2 ...
3- implementation "com.google.firebase:firebase-core:15.0.2"
4- implementation "com.google.firebase:firebase-messaging:15.0.2"
5 ...
6}

Update the manifest

  1. Open AndroidManifest.xml located inside the /android/app/src/main folder.

  2. Remove the old service block from the application.

1<application ... >
2 ...
3- <!--[START Push notification config -->
4- <service
5- android:name="com.amazonaws.amplify.pushnotification.RNPushNotificationMessagingService"
6- android:exported="false">
7- <intent-filter>
8- <action android:name="com.google.firebase.MESSAGING_EVENT"/>
9- </intent-filter>
10- </service>
11- <!-- [END Push notification config -->
12 ...
13</application>

Update your application code

Add required polyfills

You need to add the crypto.getRandomValues and URL polyfills to your application's entry point file (in most React Native apps this will be the top level index.js).

1// Example index.js
2import 'react-native-get-random-values';
3import 'react-native-url-polyfill/auto';
4...

Remove Analytics (Optional)

If you do not use Amplify Analytics in your application but have previously imported it in your code just to implement Amplify Push Notifications, you should be able to remove it now. Analytics is no longer required to be configured in your frontend application to use Amplify Push Notifications.

Replace APIs

Please refer to the Getting started portion of this guide to start learning more about the new Amplify Push Notifications.

A brief mapping of your APIs to their replacements is as follows:

Previous APIReplaced by
onRegisteronTokenReceived
onNotificationOpenedonNotificationOpened
onNotificationonNotificationReceivedInForeground
onNotificationReceivedInBackground
requestIOSPermissionsrequestPermissions

We strongly recommend you take the time to explore all the ways the new version of Amplify Push Notifications are different and all the new features that have been added. This will help you to make the best decision about how to adopt these changes for your unique use cases.