Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Feb 21, 2024

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.
amplify upgrade
  1. Pull your project (even if there are no changes) to update your configuration.
amplify pull

Replace your dependency

  1. Remove the old dependency from your project.
npm 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.
npm install @aws-amplify/rtn-push-notification@~1.1.x

Note: Amplify JavaScript v5 is only compatible with @aws-amplify/rtn-push-notification version 1.1.x

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.

platform :ios, '13.0'
  1. Install the new pods by running the following command at the root of your React Native project.
npx 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:

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

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.

buildscript {
ext {
...
minSdkVersion = 24
...
}
}
  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.

dependencies {
...
- implementation "com.google.firebase:firebase-core:15.0.2"
- implementation "com.google.firebase:firebase-messaging:15.0.2"
...
}

Update the manifest

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

  2. Remove the old service block from the application.

<application ... >
...
- <!--[START Push notification config -->
- <service
- android:name="com.amazonaws.amplify.pushnotification.RNPushNotificationMessagingService"
- android:exported="false">
- <intent-filter>
- <action android:name="com.google.firebase.MESSAGING_EVENT"/>
- </intent-filter>
- </service>
- <!-- [END Push notification config -->
...
</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).

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

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.