vicke4 / react-native-invoke-app

Bring React Native App to foreground from Headless JS
MIT License
58 stars 50 forks source link

invokeApp is not called when app is in background, DeviceEventEmitter is only called upon opening app when app is killed #8

Open whenmoon opened 4 years ago

whenmoon commented 4 years ago

I am receiving data only Firebase Cloud Messages when my Android React Native app is in the background or is killed. Here is my headless task:

AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => backgroundMessaging);

Inside my backgroundMessaging function I have this code:

const backgroundMessaging = async (message) => {
  // handle your message
  console.log(message);
  const log = { logMessage: 'this is the event emitter log' }
  invokeApp({ data: log });
  return Promise.resolve();
}
export default backgroundMessaging;

When the app is in the background the above function logs the message, but invokeApp does not seem to be called because the DeviceEventEmitter does not log anything:

    DeviceEventEmitter.addListener('appInvoked', (data) => {
      const { logMessage } = data;
      console.log(logMessage)
    });

However, when the app is killed (not in background), once I open the app the DeviceEventEmitter function logs the logMessage.

At no point does the app come to the foreground.

whenmoon commented 4 years ago

I have figured out that my issue is actually the same issue as this one.

Alarees commented 4 years ago

hi if you are using react native firebase v >6, as they say:

This method must be called outside of your application lifecycle, e.g. alongside your AppRegistry.registerComponent() method call at the the entry point of your application code.

setBackgroundMessageHandler i use it and it work's fine but the the app open's and NativeEventEmitter is not working PS : DeviceEventEmitter is deprecated as in stackoverflow Question if you have another idea please share it

vmehar13 commented 1 year ago

IMG_20230725_171146.jpg

You need to be "Allowed" "Display over other apps" from "App Info" manually.

asfaqehussain commented 2 months ago

IMG_20230725_171146.jpg

You need to be "Allowed" "Display over other apps" from "App Info" manually.

Thank you so much. Helped me a lot