Hi @mayur.bhandari,
I understand that if you can’t create a guide for now but my only point is if some one from your team could quickly try the comet chat with the latest version of any push notification library then you can see the issue I am facing.
I am using the latest version of the react-native-firebase now
"@react-native-firebase/app": "^7.1.0",
"@react-native-firebase/messaging": "^7.1.0",
"@cometchat-pro/react-native-chat": "^2.0.8"
As you suggested I sent the following payload from https://fcm.googleapis.com/fcm/send API
{
"to" : "MY_FCM_TOKEN",
"data": {
"alert": "Test",
"sound": "default",
"title": "Rohit Kumar",
"body":"Some Test Body",
"message": "{\"receiver\":\"918888863333\",\"data\":{\"metadata\":{\"@injected\":{\"extensions\":{\"profanity-filter\":{\"message_clean\":\"Test\",\"profanity\":\"no\"}}}},\"entities\":{\"receiver\":{\"entityType\":\"user\",\"entity\":{\"lastActiveAt\":1590212799,\"uid\":\"918888863333\",\"role\":\"customer\",\"name\":\"Rohit Kumar\",\"status\":\"available\"}},\"sender\":{\"entityType\":\"user\",\"entity\":{\"lastActiveAt\":1590212799,\"uid\":\"917795523234\",\"role\":\"customer\",\"name\":\"Rohit Kumar\",\"status\":\"available\"}}},\"text\":\"Test\"},\"sender\":\"917795523234\",\"conversationId\":\"917795523234_user_918888863333\",\"receiverType\":\"user\",\"id\":\"570\",\"sentAt\":1590212953,\"category\":\"message\",\"type\":\"text\",\"updatedAt\":1590212953}"
}
}
But, I am receiving the payload in onMessage but it is not being shown as notification because it doesn’t have a notification object json in it.
We also have some notification in our server and the sample payload sent from our server using the same fcm API is something like this
{
"to" : "MY_FCM_TOKEN",
"notification": {
"body": "Some Test Message",
"title": "Some Test title",
"sound": "default"
},
"data" : {
"route" : "Home"
}
}
This payload works perfectly and we receive the notification.
The main issue is with latest updates of all the push-notification libraries they have stopped showing data only notification as a notification because they are supoose to be silent notification as per Android and iOS guidelines. I think you should also make this change in your server by changing the payload structure. Anyway if anyone from your team wants to quickly try it, here is the code
//RemotePushTest.js
import { useEffect } from "react"
//import { getFCMToken, saveFCMToken } from "../../services/Helper"
import messaging from '@react-native-firebase/messaging';
import AsyncStorage from "@react-native-community/async-storage";
const storeFCMToken = async (token) => {
try {
let fcmToken = await AsyncStorage.getItem('fcmToken') || '' //await getFCMToken()
console.log('Saved fcm token', fcmToken)
if (fcmToken.localeCompare(token) != 0) {
console.log('FCM Token Has changed')
await AsyncStorage.setItem('fcmToken', token)
//await saveFCMToken(token)
}
} catch (error) {
}
}
const RemotePushTest = ({ navigation }) => {
useEffect(() => {
messaging().onNotificationOpenedApp(remoteMessage => {
console.log(
'Notification caused app to open from background state:',
remoteMessage.notification,
);
//navigation.navigate(remoteMessage.data.type);
});
// Check whether an initial notification is available
messaging()
.getInitialNotification()
.then(remoteMessage => {
if (remoteMessage) {
console.log(
'Notification caused app to open from quit state:',
remoteMessage.notification,
);
//setInitialRoute(remoteMessage.data.type); // e.g. "Settings"
}
});
// Get the device token
messaging()
.getToken()
.then(token => {
console.log('FCM Token', token)
return storeFCMToken(token);
});
// Listen to whether the token changes
return messaging().onTokenRefresh(token => {
storeFCMToken(token);
});
}, []);
useEffect(() => {
const unsubscribe = messaging().onMessage(async remoteMessage => {
console.log('A new FCM message arrived!', JSON.stringify(remoteMessage));
});
return unsubscribe;
}, []);
return null
}
export default RemotePushTest
and in your App.js just include
<RemotePushTest />
Lastly, I didn’t see any workaround in your last answer. Can you repeat it again if that’s okay?