You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am receiving remote notifications via FCM. One minor issue I have is using the onForeground event to detect notification tap only works for iOS and for Android, I have to use getInitialNotification from the RNFCM package. This function does not work for iOS so I have to conditionally call both functions when handling the notification open event.
I have attached the code snipped below.
const notificationOpenHandler = async (
notifMessage:
| Notification
| undefined
| FirebaseMessagingTypes.RemoteMessage
| null,
): Promise<void> => {
try {
// checks whether the group id is available or not
// then open the respective group chat screen
if (notifMessage?.data?.group_id) {
navigation.navigate(chatScreen, {
groupId: String(notifMessage.data.group_id),
});
}
} catch (e) {
sentryError(
`Unexpected error occured when opening group ${
notifMessage?.data?.group_id
} from notification.
Error Details: ${(e as Error).message}`,
);
}
};
// handling of notification click
useEffect(() => {
if (Platform.OS === 'ios') {
const foregroundEvent = notifee.onForegroundEvent(({type, detail}) => {
const {notification} = detail;
if (type === EventType.PRESS) {
notificationOpenHandler(notification);
}
});
const unsubscribe = notifee.onForegroundEvent(foregroundEvent);
return unsubscribe();
} else if (Platform.OS === 'android') {
// Check more docs here: https://rnfirebase.io/messaging/notifications
messaging()
.getInitialNotification()
.then(notificationOpenHandler)
.catch(e =>
sentryError(
'Unexpected problem occured when opening app from quitted state' +
e.message,
),
);
const unsubscribe = messaging().onNotificationOpenedApp(
notificationOpenHandler,
);
return unsubscribe;
} else {
return;
}
}, []);
Although this works, is there a function which could work for both platforms? Having two separate functions being conditionally called doesn't seem very good in terms of code quality.
Thank you
The text was updated successfully, but these errors were encountered:
Hello 👋, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
This issue will be closed in 15 days if no further activity occurs.
I am receiving remote notifications via FCM. One minor issue I have is using the
onForeground
event to detect notification tap only works for iOS and for Android, I have to usegetInitialNotification
from the RNFCM package. This function does not work for iOS so I have to conditionally call both functions when handling the notification open event.I have attached the code snipped below.
Although this works, is there a function which could work for both platforms? Having two separate functions being conditionally called doesn't seem very good in terms of code quality.
Thank you
The text was updated successfully, but these errors were encountered: