- ForegroundState
// any component you want
useEffect(() => {
const unsubscribe = messaging().onMessage(async (message) => {
// work
});
return unsubscribe;
}, []);
- Background state
This is in Android
// outside your app as register background handler inside => index.js
messaging().setBackgroundHandler(async () => {
// work
});
This is in IOS, Manually insert it
function isHeadless(({isHeadless}) => {
if(isHeadless){
return null;
}
return <App />
})