android – Got errors when i tried to implement foreground notification or onscreen notification


**Tried to run in ipad and after splash screen i got errors **
changes for foreground push notification

 Invariant Violation: `new NativeEventEmitter()` requires a non-null argument., js engine: hermes
ERROR  Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
    A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
ERROR  Invariant Violation: Failed to call into JavaScript module method       AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
    A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

**
I have tried below code with installation and configuration **


import PushNotificationIOS from "@react-native-community/push-notification-ios";
import React, { useEffect } from "react";
import messaging from "@react-native-firebase/messaging";
import { Platform } from "react-native";
import PushNotification from "react-native-push-notification";

const ForegroundHandler = () => {
  useEffect(() => {
    const unsubscribe = messaging().onMessage((remoteMessage) => {
      console.log("handle in foreground", remoteMessage);
      const { notification, messageId } = remoteMessage;

      if (Platform.OS == "ios") {
        PushNotificationIOS.addNotificationRequest({
          id: messageId,
          body: notification.body,
          title: notification.title,
          sound: "default",
        });
      } else {
        PushNotification.localNotification({
          body: "android body",
          title: "android notif title",
          soundName: "default",
          vibrate: true,
          playSound: true,
        });
      }
    });
    return unsubscribe;
  }, []);
  return null;
};

export default ForegroundHandler;

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img