Stable react native remote push notifications based on FCM (Android) and APNs (iOS). Compatible with newer than RN 61.5
-
Proper workflow when user tap on notification
-
Merging multiple notifications into one big InboxStyle notification using defined payload key
-
Setting title and content text keys to define android notifications (solution - how to show android notifications while app is killed)
-
Fire
yarn add react-native-super-push@git+https://github.com/rkostrab/react-native-super-push.git#1.3.1 -
Download your
google-services.jsonfile and place it inandroid/appdirectory -
Edit project-level
build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
+ classpath 'com.google.gms:google-services:4.3.3'
}- Edit app-level
build.gradle
apply plugin: "com.android.application"
+ apply plugin: 'com.google.gms.google-services'- Edit
android/app/src/main/AndroidManifest.xml:
+ <uses-permission android:name="android.permission.VIBRATE" />
<application>
+ <service
+ android:name="sk.rkostrab.push.MessagingService"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="com.google.firebase.MESSAGING_EVENT"/>
+ </intent-filter>
+ </service>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
+ android:launchMode="singleTop"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>We're using PushNotificationIOS from react-native-community so follow this guide
import PushNotificationIOS from "@react-native-community/push-notification-ios";
RNSuperPush.configure({
// required
// android only: key from notification payload which will be title of notification
titleKey: "title",
// required
// android only: key from notification payload which will be content text of notification
contentKey: "message",
// optional (if not set: will not merge notifications)
// android only: key from notification payload which will be used to merge multiple into one big InboxStyle notification
mergeKey: "type",
// optional (if not set: mipmap/ic_launcher)
// android only: define small icon into notifications from android res directory
smallIcon: "mipmap/ic_notification_small",
// required
// android only: define channel name for android Oreo and above
channelName: "Notifications",
onOpenNotification: (payload) => {
console.log(JSON.stringify(payload));
},
onGetToken: (token) => {
console.log(token);
},
onRequestPermissions: (granted, errMsg) => {
console.log("Permissions: " + granted);
},
});// request permission to receive push notifications (they are requested automatically every app start)
RNSuperPush.requestPermissions();
// dismiss all app's notifications from system tray
RNSuperPush.dismissAllNotifications();
// get token (it is requested automatically every app start)
RNSuperPush.getToken();- Push notifications are not incoming - Make sure your
package_nameingoogle-services.jsonfile is same with your apps's package name. If not then changeapplicationIdinandroid/app/build.gradleto matchpackage_namefromgoogle-services.json
Right now, I am supporting this library for only my own purposes - a few RN based apps. I am going to add more configurable features later.