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

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 .

Related

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

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.
`

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.

Cancel sent Web Push notifications

I'm sending push notifications to my website users when they (for example) receive a private message.
That notification goes to all browsers subscribed for that user. So could be desktop, mobile, work computer etc.
What I would like to do is close all the sent notifications once the user has a read a message.
So user logs in on mobile, reads the private message - at this point I want all the previously sent notifications for that PM to be closed/cancelled.
Is this possible?
Thanks in advance!
Matt
Yes this is possible, but not silently. For example, Chrome will replace the notification with a new one saying "This site has been updated in the background".
There are two separate APIs: the Push API which "gives web applications the ability to receive messages pushed to them from a server", and the Notification API which "is used to configure and display desktop notifications to the user".
The Notification API provides Notification.close(), which cancels the display of a notification.
You can use the Push API to trigger Notification.close(). Here's a sample which should go in your service worker:
self.addEventListener('push', async event => {
const data = event.data.json();
if (data.type === 'display_notification') {
self.registration.showNotification(data.title, data.options);
} else if (data.type === 'cancel_notification') {
const notifications = await self.registration.getNotifications({
tag: data.notificationTag
});
for (notification of notifications) {
notification.close();
}
} else {
console.warn("Unknown message type", event, data);
}
});
However! This design means that your cancel_notification message won't display a notification. This violates some browser policies, for example Chrome will display a new notification saying "This site has been updated in the background".

Notification Categories

I have created one of the mobile application using ionic 1 and firebase. Now I want to create a notification categories like channel where user can select which notification they needed.
Here I have shared the code for push notification which i have used and this code is working , i want to create the notification categories, the above code is working for push notification for my mobile application.
Now I need a help that how can I create the channel notification categories in my mobile application
FCMPlugin.onNotification(function(data){
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
alert( JSON.stringify(data) );
}else{
//Notification was received in foreground. Maybe the user needs to be notified.
alert( JSON.stringify(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 :)