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.
1amplify upgrade
- Pull your project (even if there are no changes) to update your configuration.
1amplify pull
Replace your dependency
- Remove the old dependency from your project.
1npm uninstall @aws-amplify/pushnotification
- 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.
-
Open
Podfile
located inside the/ios
folder of your React Native project with a text editor. -
Update
platform :ios
to at least13.0
.
1platform :ios, '13.0'
- Install the new pods by running the following command at the root of your React Native project.
1npx 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:
1#import "AppDelegate.h"2#import "AmplifyPushNotification.h"3
4...
- 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 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.js2import '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 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.