zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.75k stars 2.05k forks source link

null is not an object (evaluating 'RNPushNotification.getInitialNotification') #2302

Closed kindthr closed 10 months ago

kindthr commented 2 years ago

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)

pahmi-alifya commented 2 years ago

same issue, how to solved?

mayankgahlot commented 2 years ago

use this npm install react-native-push-notification --save

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.