question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[notifee] no background event handler has been set. Set a handler via the "onBackgroundEvent" method.

See original GitHub issue

This 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:closed
  • Created a year ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
williamtran29commented, Aug 16, 2022

This need to be fix asap. Thanks

4reactions
mikehardycommented, Aug 24, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found