Firebase Cloud messaging push notification not showing after flutter web app terminated - flutter

I am implementing the firebase cloud messaging to make my push notification service for a project but I am at a block, if I close down the tab which means I close my flutter web application I do not get the notifications that were sent whilst the time my app was closed in my browser.
I have looked through different threads here suggesting i remove the notification key from the message I am sending to FCM.
Please refer to the payload sent:
> {
"to" :[ "xxxxxxxxxx"]
"data" : {
"body" : "Notification Body",
"title": "Notification Title",
"key_1" : "Value for key_1f",
"key_2" : "Value for key_2"
}
}
The problem though still remains when I close the tab running my flutter web app and send a notification, I do not receive it when I open the app in a new tab again.
Essentially I have to provoke the onMessageReceived() function but I guess this would not be in my case. Is it different because the thread(link) are based on mobile apps and not web applications.
`

Related

Huawei PushKit Notifications doesn't appear when app is killed or in background

I have integrated the Huawei Push kit to my app and when I trigger a notification from Huawei Push Kit Console, I can receive the notification when the app is in background. However, when our system backend triggers Huawei API to push notifications, it doesn't appear when the app is in the background.
Following code is getting executed despite the app is in foreground or background but Notification parameters such as Title etc, coming as null. Notification object itself is not null.
Contents of the JSON message can be received as a single String from remoteMessage.getData() but values does not mapped to respective fields.
public class HuaweiNotificationHandler extends HmsMessageService{
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i(TAG, "getData: " + remoteMessage.getData()
RemoteMessage.Notification notification = remoteMessage.getNotification();
if (notification != null) {
Log.i(TAG, "getTitle: " + notification.getTitle()
}
}
}
Our backend executes this API provided by Huawei to send data messages.
This is the format of our JSON
{
"collapseKey":"dummykey",
"priority":"high",
"delayWhileIdle":false,
"dryRun":false,
"sound":"",
"contentAvailable":true,
"data":{
"data":{
"type":"A",
"id":"1111111",
"entity":"0",
"url":""
},
"restrictedPackageName":"com.aa.bb.cc" // this package name is exactly same as the huawei app package registered
},
"notification":{
"title":"Notification Title",
"icon":"ic_launcher",
"body":"Message"
}
}
UPDATE
Sample code of a typical data message:
{
"validate_only": false,
"message": {
"data": "{'param1':'value1','param2':'value2'}",
"token": [
"pushtoken1",
"pushtoken2"
]
}
}
For Details,see Docs.
Push Kit supports two types of messages: notification messages and data messages.
After a device receives a data message, the device transfers it to your app instead of directly displaying the message. Your app then parses the message and triggers the corresponding action. Push Kit only functions as a channel, and the delivery of data messages depends on the resident status of your app. However, notification messages can still be delivered even if your app is not launched.
For the sake of saving power and not disturbing users, your app will not be launched by Push Kit after being stopped, and no data messages can be delivered to your app. In this case, you can determine whether to use notification messages based on your services.
From: https://stackoverflow.com/a/64100678/14006527
Alternatively, you can set High-priority data messages to forcibly launch your stopped app to receive and process the messages.

Google Home report state request is working but not showing expected result?

I'm integrating google assistant with my application. The problem is when I send a report state request to assistant while inside a device screen in google home application, I get a 200 OK response with the requestId I'm sending, but the device screen doesn't update with the device state. (It gets updated after I go back and go to device screen again but that is done through query intent)
Sample Request Body
{
"payload" : {
"devices" : {
"states" : {
"12364" : {
"on" : true
}
}
}
},
"requestId" : "A7TNpoXlnG0OQWzpTvJAa4sjolAAt46q",
"agentUserId" : "14556"
}
Sample Response Body
{ "requestId" : "A7TNpoXlnG0OQWzpTvJAa4sjolAAt46q" }
This is their documentation regarding the report state.
I even deployed the report state dashboard locally to monitor the state changes but it doesn't update as well.
Can anyone point me in right direction? Thanks!
The behavior of different Assistant surfaces with respect to Home Graph changes can vary, so it's best not to rely on looking for real-time UI changes in the Google Home app.
The Report State Dashboard noted in the documentation that you linked is a good way to validate the state you publish to Home Graph graphically. We also recently published an AoG ProTips episode on this topic that shows you how to do the same from the command line.
Neither of these methods will update automatically in real-time either, but you can refresh them after publishing a state change to verify the right data is in Home Graph.

APNs works fine separate from Firebase, but cannot get notifications to work in FCM

Sorry if this is a dumb question, I am setting up Firebase with APNs for the first time. I am working in Swift with an iOS app and I have apns messages working separately without Firebase -- so remote push notifications are received on the device in background and while running app. I can use this tool https://github.com/noodlewerk/NWPusher to send notifications on Sandbox and Production apns certs successfully by sending this json blob as an example:
{"aps":{"alert":"Testing","badge":1,"sound":"default"}}
However, now I am trying to incorporate Firebase and not getting the same behavior on the iOS device.
I have Firebase messaging setup and the app prints remote messages with "shouldEstablishDirectChannel = true" but APNs is never received (with this set to false then device doesn't print anything). No push notifications are received on device. I don't believe APNs is being mapped correctly for Firebase messages as I cannot get the device to display push notifications in the same way that I can with NWPusher on strictly APNs Sandbox and Production certs. Firebase app console has the app's .p12 apns cert (which is working fine for apns without firebase involved)
Here's a sample request I try to send to https://fcm.googleapis.com/fcm/send
{
"to" : "eqkeyhereinifnbe",
"collapse_key" : "type_a",
"data" : {
"body" : "Notification",
"title": "testing",
"key_1" : "Data for key one",
"key_2" : "Hello Meowww",
}
}
API returns a success response:
{
"multicast_id": 634054476369,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:15329261441bfd36cccfb49c"
}
]
}
In iOS app's AppDelegate:
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)!")
}
^prints the message successfully from the api on device:
Received data message: [AnyHashable("collapse_key"): type_a,
AnyHashable("key_1"): Data for key one, AnyHashable("from"): 9861340,
AnyHashable("key_2"): Hello Meowww, AnyHashable("body"): Notification,
AnyHashable("title"): testing]!
However this received message doesn't do any of the APNs notification magic to an iOS device. I tried to send the same json blob to Firebase API that works fine in NWPusher: {"aps":{"alert":"Testing","badge":1,"sound":"default"}}, but device does not display the notification. Why? How troubleshoot this to make Firebase send the same APNs notification to show notifications on device?
I just needed to write the request with "message" and "data" objects like this:
{
"to" : "aTokenHerefonsfondfodnfdofndf",
"collapse_key" : "type_a",
"notification":{
"title":"Notification title test",
"body":"It worked body"
},
"data" : {
"body" : "Notification",
"title": "testing",
"key_1" : "Data for key 1",
"key_2" : "Hello Meowww"
}
}

Ionic FCM push notification not received when app is opened and screen locked unless it's tapped

I'm developing an ionic application and I'm using FCM push notification to send notifications to the user.
This is the JSON payload of the sent notification :
{
"to" : "access_token",
"priority": "normal",
"notification" : {
"body" : "this is message",
"title" : "notification Title"
},
"data": {
"link": ....
}
}
The push notification is received in these different cases :
when the app is in background or it is killed --> the user will
receive a system tray push notification
when the app is in foreground and the user is in it --> the user will receive the new data that will update the app
when the app is in foreground and the screen is locked (the system considers it as in background) --> So the user will receive a
system tray push notification but when unlocking the screen of the phone,
nothing happens in the app instance that were in foreground until I click on the push notification in the system tray.
Is there any way to get the data of a push notification that is in the system tray without clicking on it ?
Hope this work!
For Foreground you can use Local Notification to show up push notification :
https://ionicframework.com/docs/native/local-notifications/
send the notification information along with data object and then , in your ionic project
manually set a notification with that data .

Push Notification FCM doesnt appear when app is in background

I want to implement the FCM Push Notification service for a chat app, I follow the step in the Firebase doc , Im getting notifications when they are sent from the Firebase console to my device.
When I try to send the notification using my server side to the device through FCM using http post to https://fcm.googleapis.com/fcm/send :
my headers are :
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
my body is :
{ "notification": {
"title": "Portugal vs. Denmark",
"text": "5 to 1"
},
"to" : "myDeviceRegistrationId"
}
When my app is in background , nothing is happening (I repeat myself but with the console, I am getting the notification in background )
When the app is active and I am sending this notification to my device, Im getting the following message in my console Log, So I suppose that I am getting the notification but for some reason its not displaying it in background
Message ID: 0:1470132526023119%8d989dbf8d989dbf
%# [aps: {
alert = {
body = "5 to 1";
title = "Portugal vs. Denmark";
};
}, gcm.message_id: 0:1470132526023119%8d989dbf8d989dbf]
2016-08-02 13:08:46.913 ProjectAlpha[13324:4726432] Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.
what am I missing ?
thanks for your help..
Did you active background mode?
Look this
I fixed my issue by deleting the
FirebaseAppDelegateProxyEnabled
key from Info.plist and using
"content_available": true
to receive messages while application is in background.
Now it works perfectly :)