react-native-invoke-app icon indicating copy to clipboard operation
react-native-invoke-app copied to clipboard

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

Open whenmoon opened this issue 6 years ago • 4 comments

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 avatar Nov 02 '19 16:11 whenmoon

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

whenmoon avatar Nov 03 '19 15:11 whenmoon

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

Alarees avatar Dec 26 '19 23:12 Alarees

IMG_20230725_171146.jpg

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

vmehar13 avatar Jul 25 '23 11:07 vmehar13