evollu / evollu/react-native-fcm
FCM callback is running twice in iOS when app is in Foreground
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 661
- PR merge metrics
- No merged PRs in 30d
Description
In my app I am using FCM callback to show notification when app is in Foreground as below
componentDidMount() {
this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
if (Platform.OS === 'ios') {
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;
}
if (notif.aps.alert.body) {
FCM.setBadgeNumber(this.props.notificationCount+1);
this.props.addNotification(notif.aps.alert.body);
//alert(notif.aps.alert.body);
Alert.alert(
'Notification',
notif.aps.alert.body,
[
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{ cancelable: false }
)
return
}
} else {
if (notif.fcm.body) {
this.props.addNotification(notif.fcm.body);
//alert(notif.fcm.body);
Alert.alert(
'Notification',
notif.fcm.body,
[
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{ cancelable: false }
)
return
}
}
});
}
componentWillUnmount() {
this.notificationListener.remove();
}
And above code is showing me alert for notification twice so its triggering twice.
Please check below information as well
1. What version of RN and react-native-fcm are you running?
"react-native": "^0.48.3","react-native-fcm": "^10.0.3",
2. What device are you using? (e.g iOS9 emulator, Android 6 device)?
iPhone 6s Plus
3. Is your app running in foreground, background or not running?
Foreground.
Please provide solution ASAP
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.