Configure iOS manual installation
masterPushNotificationIOS for iOS support. You must follow the specific installation instructions for react-native-push-notification-ios to ensure iOS notifications work correctly.repository·master·Indexed 27 days ago
https://github.com/zo0r/react-native-push-notificationA library for handling both local and remote push notifications in React Native applications for iOS and Android. Version 8.1.1 supports triggering immediate local notifications, scheduling notifications for specific times or repeating intervals, and managing Android notification channels. It includes features for custom notification sounds, inline replies on Android, and integration with Firebase and Play Services for remote notifications.
PushNotificationIOS for iOS support. You must follow the specific installation instructions for react-native-push-notification-ios to ensure iOS notifications work correctly.To use custom sounds, place the audio files in the following locations:
[project_root]/android/app/src/main/res/rawResources in Xcode.In the notification options object, specify the filename using soundName:
soundName: 'my_sound.mp3'
Install the package using your preferred package manager.
npm install --save react-native-push-notification
# OR
yarn add react-native-push-notificationAndroid allows adding interactive buttons to notifications via the actions parameter (an array of strings).
To enable inline text input, add "ReplyInput" to the actions array. You must also provide reply_placeholder_text and reply_button_text.
To retrieve the user's response in your onNotification handler, check the action property and access notification.reply_text.
Requirement: You must add the following receiver to your AndroidManifest.xml:
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />// Schedule a notification with inline reply
PushNotification.localNotificationSchedule({
message: "My Notification Message",
date: new Date(Date.now() + (60 * 1000)),
actions: ["ReplyInput"],
reply_placeholder_text: "Write your response...",
reply_button_text: "Reply"
});
// Handling the reply in onNotification
// ...
if(notification.action === "ReplyInput"가){
console.log("texto", notification.reply_text)
}When using remote notifications, ensure firebase-messaging and google-services are correctly configured in your Gradle files. Note that firebase-core is no longer needed; use firebase-analytics instead.
// In android/build.gradle
ext {
googlePlayServicesVersion = "<Your play services version>"
firebaseMessagingVersion = "<Your Firebase version>"
// ... other settings
}
buildscript {
dependencies {
classpath('com.google.gms:google-services:4.3.3')
}
}
// In android/app/build.gradle
dependencies {
implementation 'com.google.firebase:firebase-analytics:17.3.0'
}
apply plugin: 'com.google.gms.google-services'If your 3rd party notification provider uses a custom data format that react-native-push-notification cannot parse, you must implement a custom IntentHandler in your Android native code (Application init or MainActivity.onCreate()).
AndroidManifest.xml.onNewIntent to parse the intent.getBundleFromIntent to return the bundle that will be serialized into notification.data for the onNotification() handler.// Android Native Implementation
RNPushNotification.IntentHandlers.add(new RNPushNotification.RNIntentHandler() {
@Override
public void onNewIntent(Intent intent) {
// Custom parsing logic here
}
@Nullable
@Override
public Bundle getBundleFromIntent(Intent intent) {
if (intent.hasExtra("MY_NOTIFICATION_PROVIDER_DATA_KEY")) {
return intent.getBundleExtra("MY_NOTIFICATION_PROVIDER_DATA_KEY");
}
return null;
}
});You can define a default notification channel in your AndroidManifest.xml to avoid manual channel management for local notifications.
For react-native-push-notification, use the following metadata:
<meta-data
android:name="com.dieam.reactnativepushnotification.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />If this is not defined, the library falls back to the Firebase default channel ID: fcm_fallback_notification_channel.
You can schedule notifications to repeat at specific intervals.
Use repeatType. Supported values: month, week, day, hour, minute.
Note: repeatTime is not supported on iOS.
Use repeatType. Supported values: month, week, day, hour, minute, time.
If repeatType is set to time, you must provide repeatTime as the number of milliseconds between intervals.
// Android example: Every other day
PushNotification.localNotificationSchedule({
...
repeatType: 'day',
repeatTime: 2,
...
});To use localNotificationSchedule(), you must manually update your AndroidManifest.xml with specific permissions, metadata, and receivers. Note that localNotification() works without these changes.
<!-- In android/app/src/main/AndroidManifest.xml -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application ....>
<!-- Set to true to enable pop-up for in foreground on receiving remote notifications -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="false"/>
<!-- Set your App's accent color -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="@color/white"/>
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>Android requires notification channels to be created before they can be used. When triggering a notification, you must provide a channelId that matches a created channel.
Note: Once a channel is created, its options cannot be updated. To change channel settings, you must create a new channel with a different channelId.
Use PushNotification.createChannel(options, callback) to register a channel. The callback returns true if the channel was newly created, or false if it already existed.
Use PushNotification.getChannels(callback) to retrieve an array of available channel IDs.
PushNotification.channelExists(channel_id, callback): Returns true/false if the channel exists.PushNotification.channelBlocked(channel_id, callback): Returns true/false if the channel is blocked by the user.Use PushNotification.deleteChannel(channel_id) to remove a channel.
import PushNotification, {Importance} from 'react-native-push-notification';
PushNotification.createChannel(
{
channelId: "channel-id", // (required)
channelName: "My channel", // (required)
channelDescription: "A channel to categorise your notifications", // (optional)
playSound: false,
soundName: "default",
importance: Importance.HIGH,
vibrate: true,
},
(created) => console.log(`createChannel returned '${created}'`)
);
// List channels
PushNotification.getChannels(function (channel_ids) {
console.log(channel_ids); // ['channel_id_1']
});
// Check if exists
PushNotification.channelExists('channel-id', (exists) => {
console.log(exists); // true/false
});
// Check if blocked
PushNotification.channelBlocked('channel-id', (blocked) => {
console.log(blocked); // true/false
});
// Delete channel
PushNotification.deleteChannel('channel-id');When scheduling or creating notifications, you can customize their behavior using the following options:
Sets the priority level. Default is "high".
Options: "max", "high", "low", "min", "default".
Sets how the notification is visible. Default is "private".
Options: "private", "public", "secret".
Sets the importance level using the Importance object.
Options: Importance.DEFAULT, Importance.HIGH, Importance.LOW, Importance.MIN, Importance.NONE, Importance.UNSPECIFIED.
Initialize the notification service using PushNotification.configure().
CRITICAL: Do NOT call .configure() inside a component (even App). It must be called in the app's entry point (e.g., index.js) to ensure notification handlers are loaded correctly.
import PushNotificationIOS from "@react-native-community/push-notification-ios";
import PushNotification from "react-native-push-notification";
PushNotification.configure({
onRegister: function (token) {
console.log("TOKEN:", token);
},
onNotification: function (notification) {
console.log("NOTIFICATION:", notification);
// Required for iOS
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
onAction: function (notification) {
console.log("ACTION:", notification.action);
console.log("NOTIFICATION:", notification);
},
onRegistrationError: function(err) {
console.error(err.message, err);
},
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: true,
});