Skip to main content

I have a react native app. I am using react-native push-notification npm module for pushnotifications (mainly local notifications), this is working fine.

I use OneSignal service for remote notifications which works fine as well.

However, now I am trying to use react-native-freshchat-sdk (third party tool) to provide chat functionality within the app.

I have the following code

    PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function (token: any) {
console.log('TOKEN:', token)
dispatch(tokenGenerated(token));
},

//(required) Called when a remote or local notification is opened or received
onNotification: function (notification: any) {
console.log(`**********notification received ********************* : ${JSON.stringify(notification)}`)
Freshchat.isFreshchatNotification(notification.data, (freshchatNotification: any) => {
if (freshchatNotification) {
console.log(`**********freshchatNotification received *********************`)
Freshchat.handlePushNotification(notification.data);
} else {
console.log(`**********some other notification*********************`)
}
})
},

Things work fine when the app is in the foreground or background. I do get remote notifications from FreshChat with the chat content. FreshChat uses FCM for sending notifications. However, when the app is closed or killed, I do not get the notifications (atleast they are not shown in the tray) When I open the chat, I can see the chat message there. Chat remote notification looks like the following


{
"foreground": false,
"userInteraction": false,
"id": "-1665678567",
"data": {
"channel_id": "748134",
"app_id": "5787643203",
"notif_type": "1",
"msg_alias": "8343f922-9dfa-4fe9-9220b-61af8902e7650",
"source": "freshchat_user",
"body": "heelo world message",
"timestamp": "1660956855495",
"user_name": "Foo Bar",
"target_user_alias": "ssd1232-75df-87f0-fsdsd",
"conv_id": "6479825358242"
}
}

I have been scratching my head to understand why I am not getting remote notifications when the app is closed. What's confusing me even more is that I get OneSignal remote notifications even when the app is closed. I would like to see similar behaviour with the remote notification sent by FreshChat

Any help pointers would be really handy. I have been stuck with these for days now and have no clue what's going wrong. Thanks in advance

i hav same issue facing from nov. have you fixed yet ? freschat says its not there issue. its code level issue 


Hi i have solution why push notificaiton is not working when app is killed. its depends on how user have killed app. like in andorid we can swap and killed app so at time FCM token can’t handle payload. we need to mange how user can close app. 

 

There are a few preconditions which must be met before the application can receive message payloads via FCM:

  • The application must have opened at least once (to allow for registration with FCM).
  • On iOS, if the user swipes away the application from app Switcher, it must be manually reopened again for background messages to start working again.
  • On Android, if the user force quits the app from device settings, it must be manually reopened again for messages to start working.
  • On iOS & macOS, you must have correctly setup your project to integrate with FCM and APNs.
  • On web, you must have requested a token (via getToken) with the key of a "Web Push certificate".

 

The process of handling background messages is currently different on Android/Apple & web based platforms

 

Handling messages whilst your application is in the background is a little different. Messages can be handled via the onBackgroundMessage handler. When received, an isolate is spawned (Android only, iOS/macOS does not require a separate isolate) allowing you to handle messages even when your application is not running.

There are a few things to keep in mind about your background message handler:

  1. It must not be an anonymous function.
  2. It must be a top-level function (e.g. not a class method which requires initialization).

Reply