react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

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

Open kindthr opened this issue 3 years ago • 1 comments

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)

kindthr avatar Aug 22 '22 15:08 kindthr

same issue, how to solved?

pahmi-alifya avatar Sep 18 '22 10:09 pahmi-alifya

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

mayankgahlot avatar Sep 29 '22 11:09 mayankgahlot

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.

github-actions[bot] avatar Sep 30 '23 00:09 github-actions[bot]