My application is receiving this warning "Sending messaging_notification_received with no listeners registered" and the callback is not calling. Android works fine.
can you reproduce with example app?
Have the same issue.
I tried solution given here [https://github.com/evollu/react-native-fcm/issues/561] but still doesn't work.
I have this code in my js:
import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType} from 'react-native-fcm';
componentDidMount() {
// iOS: show permission prompt for the first call. later just check permission in user settings
// Android: check permission in user settings
FCM.requestPermissions().then(()=>console.log('granted')).catch(()=>console.log('notification permission rejected'));
FCM.getFCMToken().then(token => {
console.log(token)
// store fcm token in your server
});
FCM.getInitialNotification().then(notif => {
console.log("Initial Notification", notif)
});
this.notificationListener = FCM.on(FCMEvent.Notification, notif => {
console.log("Notification", notif);
if(notif.local_notification){
return;
}
if(notif.opened_from_tray){
return;
}
if(Platform.OS ==='ios'){
//optional
//iOS requires developers to call completionHandler to end notification process. If you do not call it your background remote notifications could be throttled, to read more about it see the above documentation link.
//This library handles it for you automatically with default behavior (for remote notification, finish with NoData; for WillPresent, finish depend on "show_in_foreground"). However if you want to return different result, follow the following code to override
//notif._notificationType is available for iOS platfrom
switch(notif._notificationType){
case NotificationType.Remote:
notif.finish(RemoteNotificationResult.NewData) //other types available: RemoteNotificationResult.NewData, RemoteNotificationResult.ResultFailed
break;
case NotificationType.NotificationResponse:
notif.finish();
break;
case NotificationType.WillPresent:
notif.finish(WillPresentNotificationResult.All) //other types available: WillPresentNotificationResult.None
break;
}
}
// direct channel related methods are ios only
// directly channel is truned off in iOS by default, this method enables it
FCM.enableDirectChannel();
this.channelConnectionListener = FCM.on(FCMEvent.DirectChannelConnectionChanged, (data) => {
console.log('direct channel connected' + data);
});
setTimeout(function() {
FCM.isDirectChannelEstablished().then(d => console.log(d));
}, 1000);
});
this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, token => {
console.log("TOKEN (refreshUnsubscribe)", token);
});
}
componentWillUnmount() {
// stop listening for events
this.notificationListener.remove();
this.refreshTokenListener.remove();
}
At console it shows:

I receive notifications in background so the problem is not something about Firebase configuration. I also have my AppDelegate with all methods implemented. Please help!
ok guys. messaging_notification_received is something part of react-native-firebase not react-native-fcm. So if you are hooking the messaging using react-native-fcm you can ignore this warning.
@evollu I'm using react-native-firebase to crash report and statistics. But seems like it is messing up with react-native-fcm and the Notification callback is not called.
@ercpereda ios or android
It's working in android, but no in iOS
@ercpereda on the remote debug do you get _undefined_ in the log of FCM.getInicialNotification()?
And it never calls FCM.on()?
Because I have that issues.
iOS, foreground.
@pipoec I going to check if that happens
@ercpereda have you followed readme to add delegate functions in appDelegate.m?
@evollu Yes, I followed the README instructions for both android and ios
Notification callback is not called. does the banner show up?
No, the banner does not show up. I just put a breakpoint in the callback and it never hits. But the notification reaches the application because every time I throw one from my backend I get the warning message.
@ercpereda looks like your react-native-firebase is handling and trapping the notification so react-native-fcm doesn't get it at all. usually it is caused by implementing react-native-firebase's hook on notifications
@pipoec Yes, I get undefined from FCM.getInicialNotification() and it never calls FCM.on()
Now it calls FCM.on() Thanks @evollu!
@ercpereda For showing foreground notifications, I added this:
this.notificationListener = FCM.on(FCMEvent.Notification, notif => {
console.log("Notification", notif);
if (AppState.currentState == 'active' && AppState.currentState != 'inactive') {
Alert.alert(notif.aps.alert)
}
@pipoec
check this
if(Platform.OS ==='ios'){
//optional
//iOS requires developers to call completionHandler to end notification process. If you do not call it your background remote notifications could be throttled, to read more about it see https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application.
//This library handles it for you automatically with default behavior (for remote notification, finish with NoData; for WillPresent, finish depend on "show_in_foreground"). However if you want to return different result, follow the following code to override
//notif._notificationType is available for iOS platfrom
switch(notif._notificationType){
case NotificationType.Remote:
notif.finish(RemoteNotificationResult.NewData) //other types available: RemoteNotificationResult.NewData, RemoteNotificationResult.ResultFailed
break;
case NotificationType.NotificationResponse:
notif.finish();
break;
case NotificationType.WillPresent:
notif.finish(WillPresentNotificationResult.All) //other types available: WillPresentNotificationResult.None
break;
}
}
notif.finish(WillPresentNotificationResult.All) will cause the banner to show up in foreground. However if Alert is what you want, your approach is good
@evollu I have that code but didn't display banner in foreground
@pipoec did you send with content_available and check if this line is hit when notification arrives
https://github.com/evollu/react-native-fcm/blob/master/Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m#L45
@evollu that was my problem. I was sending a message without the notification field and without the content_available
issue sounds resolved
Thanks to all for the help :-)
@ercpereda can you share your json structure of the notification? I put content_available key but still doesn't work.
so what's the fix? do i have to remove my app's react-native-firebase dependency? I'm also getting the messaging_notification_received on iOS
@nsarafa Remove react-native-firebase is not needed. The problem was with the param content_available, I was sending a message without the notification field and in that case content_available should be equal to false
Here's my push notification logic..
const payload = {
notification: {
body: req.body.message,
title: req.body.title,
sound: 'default',
icon: 'new',
content_available: false,
},
data: req.body.data
}
So I have to add content_availalbe: false to this object for iOS to work?
Also.. @evollu, you mentioned react-native-firebase trapping push notifications. do i have to remove that library in its entirety for iOS push notifications to work? Even with react-native-firebase my android push notifications logic still works, without getting "trapped".
notification: {
body: req.body.message,
title: req.body.title,
sound: 'default',
icon: 'new',
},
content_available: true,
data: req.body.data
then you should see this line triggered
https://github.com/evollu/react-native-fcm/blob/master/Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m#L65
or this line triggered if you are in foreground
https://github.com/evollu/react-native-fcm/blob/master/Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m#L45
@evollu
Before this when im using 6.2.3, it's working fine
I just upgrade react-native-fcm from version 6.2.3 to 15.0.2
POD:-
Firebase (4.13.0)
FirebaseMessaging (2.2.0)
In my cases this is my code send from postman
{
'to' : '',
'content_available': true,
'notification': {
'body': 'title',
'title': 'body'
},
'data': {
'custom_notification': {
'title': 'title',
'body': 'body'
}
},
'priority': 'high'
}
but I still get 'messaging_notification_received' with no listeners registered
I put NSLOG(@"test"); for both places, but there a no console with this line when I send a push message. any idea what's wrong ?
Most helpful comment
then you should see this line triggered
https://github.com/evollu/react-native-fcm/blob/master/Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m#L65
or this line triggered if you are in foreground
https://github.com/evollu/react-native-fcm/blob/master/Examples/simple-fcm-client/ios/SimpleFcmClient/AppDelegate.m#L45