I'm trying to use react native push notification in expo app so without eject the project. I'm facing a problem :
localNotification.js:
import PushNotification, {Importance} from 'react-native-push-notification';
export const handlerSystemNotification = () => {
PushNotification.localNotification({
channelId: Math.round(Math.random() * 1000000),
channelName: 'test app',
autoCancel: true,
bigText: 'body text notifiaction',
subText: '',
title: '⏳ Reminder',
message: 'lorem txt...',
playSound: true,
soundName: 'default',
importance: 10,
vibrate: true,
vibration: 1000,
importance: Importance.HIGH,
priority: "high",
})
}
App.js:
useEffect(() => {
PushNotification.configure({
onRegister: function(token) {
console.log("TOKEN:", token);
},
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log("NOTIFICATION:", notification);
// process the notification here
// required on iOS only
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
// Android only
senderID: "1090501687137",
// iOS only
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true
});
// Assume a message-notification contains a "type" property in the data payload of the screen to open
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log("Message handled in the background!", remoteMessage);
})
const unsub = messaging().onMessage(async remoteMessage=>{
Alert.alert('A new FCM msg arrived', JSON.stringify(remoteMessage))
console.log(remoteMessage);
registerForPushNotificationsAsync().then(token => setExpoPushToken(token));
return unsub;
})
}, []);
const onPress= () => {
handlerSystemNotification()
}
Error :
TypeError: null is not an object (evaluating 'RNPushNotification.getInitialNotification')
This error is located at: in App (created by ExpoRoot) in ExpoRoot in RCTView (created by View) in View (created by AppContainer) in RCTView (created by View) in View (created by AppContainer) in AppContainer in main(RootComponent)