notifee: [Android]: App is crashing after opening a notification displayed when app is killed or in background

Hi all, I am having an issue with Notifee, when displaying a notification when app is in background or killed.

This is happening even if the notification is very basic like:

const object = {
title: 'Dummy data',
body: 'Dummy data',
android: {
channelId: 'default' //I am generating this one
}
}

notifee.displayNotification(object);

In emulator, I can see this error message when the notification is triggered and also when I click on it:

TypeError: Cannot read properties of undefined (reading 'then') Screenshot 2023-01-12 at 4 18 23 PM

In production build, it will crash in the moment I click in notification.

My dependencies are:

“react-native”: “0.70.6”, “@notifee/react-native”: “7.3.0”

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18 (3 by maintainers)

Most upvoted comments

@helenaford thank you very much for your effort, I just found the issue, I totally forgot notifee.onBackgroundEvent to make it asynchronous, Iw as only checking messaging().onBackgroundMessageReceived LOL.

So the issue was that I had to make notifee.onBackgroundEvent function asynchronous (add async), nothing else.

Will close this ticket.

I have solved my issue, ‘taskProvider’(AppRegistry.js) returns a non-Promise value, you can wrap it in a Promise Promise.resolve(taskProvider()(data)) .then(() => { if (NativeHeadlessJsTaskSupport) { NativeHeadlessJsTaskSupport.notifyTaskFinished(taskId); } }) .catch(reason => { console.error(reason); if ( NativeHeadlessJsTaskSupport && reason instanceof HeadlessJsTaskError ) { NativeHeadlessJsTaskSupport.notifyTaskRetry(taskId).then( retryPosted => { if (!retryPosted) { NativeHeadlessJsTaskSupport.notifyTaskFinished(taskId); } }, ); } });

I have solved my issue, you must have to make async function just like this otherwise your app will crash when you tap on notification

async function onMessageReceived(remoteMessage) {
  // Do something
  console.log('Message handled in the background!', JSON.stringify(remoteMessage));
   
}

messaging().onMessage(onMessageReceived);
messaging().setBackgroundMessageHandler(onMessageReceived);