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
- Make sure you are using the latest version of the Amplify CLI.
amplify upgrade
- Pull your project (even if there are no changes) to update your configuration.
amplify pull
Replace your dependency
- Remove the old dependency from your project.
npm uninstall @aws-amplify/pushnotification
- Add the new native module to your project.
npm install @aws-amplify/rtn-push-notification@~1.1.x
Update build configurations
Update your Podfile
Amplify Push Notifications now requires a minimum target of iOS 13.0.
-
Open
Podfile
located inside the/ios
folder of your React Native project with a text editor. -
Update
platform :ios
to at least13.0
.
platform :ios, '13.0'
- Install the new pods by running the following command at the root of your React Native project.
npx pod-install
Update your Application Delegate
-
Reverse the steps previously taken to augment your
AppDelegate
-
Locate and open your
AppDelegate.m
orAppDelegate.mm
file in your text editor. You should find it in your React Native project under/ios/<your-project-name>
-
At the top of your
AppDelegate
, import Amplify Push Notifications:
#import "AppDelegate.h"#import "AmplifyPushNotification.h"
...
- 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.
-
Open
build.gradle
located inside the/android
folder of your React Native project with a text editor. -
Update the
minSdkVersion
value in thebuildscript
block to at least24
.
buildscript { ext { ... minSdkVersion = 24 ... }}
-
Open the application
build.gradle
located inside the/android/app
folder of your React Native project with a text editor. -
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
-
Open
AndroidManifest.xml
located inside the/android/app/src/main
folder. -
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.jsimport '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 API | Replaced by |
---|---|
onRegister | onTokenReceived |
onNotificationOpened | onNotificationOpened |
onNotification | onNotificationReceivedInForeground onNotificationReceivedInBackground |
requestIOSPermissions | requestPermissions |
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.