I'm trying to implementing local notification in IOS using this @react-native-community/push-notification-ios package.
I followed all the documentation properly. Still, LocalNotification is not working.
This is my environment config:
- react-native
: 0.61.4
- @react-native-community/push-notification-ios --save
: 1.0.5
I did the following things,
npm i @react-native-community/push-notification-ios --save
cd ios && pod install
AppDelegate.m
as per described hereimport PushNotificationIOS from "@react-native-community/push-notification-ios";
.
.
.
componentDidMount(){
PushNotificationIOS.addEventListener('localNotification', this._onNotification);
PushNotificationIOS.requestPermissions();
PushNotificationIOS.presentLocalNotification({
alertBody: 'Test Notification'
});
}
_onNotification(notification) {
console.log(notification._alert);
}
.
.
.
console.log
of notification but not getting any local notification.Well, when the app running in the foreground, you won't be able to see the notification. You can call the local schedule function and quick hide app to the background, then you will see the notification.
Source Code:-
PushNotificationIOS.localNotificationSchedule({
message: "Local push notification", //mandatory
number: 1,
date: new Date(Date.now() + (5 * 1000)) // Schedule in 5 secs
});