[notifee] no background event handler has been set. Set a handler via the "onBackgroundEvent" method.
See original GitHub issueThis warning appears when I launch a test notification with FCM. The notification appears twice in background mode (I don’t know why twice), and once in foreground mode.
This warning only appears in background mode.
index.js
import { registerRootComponent } from 'expo';
import Notification from '@/configs/Notification';
import notifee from '@notifee/react-native';
import messaging from '@react-native-firebase/messaging';
import App from './App';
Notification.getFCMToken();
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
notifee.displayNotification({
title: remoteMessage.notification.title,
body: remoteMessage.notification.body,
android: {
channelId: 'default',
}
});
});
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in Expo Go or in a native build,
// the environment is set up appropriately
registerRootComponent(App);
Notification.getFCMTOken
getFCMToken: async () => {
const hasPermission = await messaging().hasPermission();
if (!hasPermission) {
await messaging().requestPermission();
}
await messaging().registerDeviceForRemoteMessages();
const token = await messaging().getToken();
if (token) {
userDetails = await firestore()
.collection('users')
.doc(auth().currentUser.uid)
.get();
if (userDetails.exists) {
userToken = userDetails.data().fcmToken;
if (userToken != token) {
firestore()
.collection('users')
.doc(auth().currentUser.uid)
.update({
fcmToken: token,
});
}
}
}
},
App.js
import React from 'react';
import { store } from "./app/redux/store";
import { Provider } from "react-redux";
import AppNavigator from './app/navigation/AppNavigator';
import { SafeAreaView } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import notifee from '@notifee/react-native';
import messaging from '@react-native-firebase/messaging';
export default function App() {
React.useEffect(() => {
return messaging().onMessage(async (remoteMessage) => {
notifee.displayNotification({
title: remoteMessage.notification.title,
body: remoteMessage.notification.body,
android: {
channelId: 'default',
}
});
});
}, []);
return (
<SafeAreaView style={{
flex: 1,
}}>
<StatusBar
style="light-content"
animated={true}
translucent={true}
/>
<Provider store={store}>
<AppNavigator />
</Provider>
</SafeAreaView>
);
}
Issue Analytics
- State:
- Created a year ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
onBackgroundEvent - Notifee
The handler must return a Promise once complete and only a single event handler can be registered for the application. View the Background...
Read more >React-Native navigate after a notification press - Stack Overflow
We've tried using the useNavigation() in the notifee.onBackgroundEvent() but we keep getting an Invalid hook call. When we try to pass the ...
Read more >Push Notifications (V2) | Stream Chat - React Native SDK Docs
To listen to notifications in the background, you can use the setBackgroundMessageHandler method. caution. This handler works only on Android. For this handler...
Read more >notifee - Bountysource
Schedule a notification via Trigger; Kill the app; No notification fired at the specified time ... Handler.dispatchMessage (Handler.java:105) android.os.
Read more >React Native push notifications with Firebase | collective:mind
Notifee provides us with a variety of methods for handling the received messages, such as displaying a notification, setting up foreground and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This need to be fix asap. Thanks
@williamtran29 I eagerly await your fix!
https://hackernoon.com/i-thought-i-understood-open-source-i-was-wrong-cf54999c097b
Your comment is specifically demotivating probably not what you want