react-native-invoke-app
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
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.
I have figured out that my issue is actually the same issue as this one.
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
You need to be "Allowed" "Display over other apps" from "App Info" manually.