Ionic 4 FCM.onNotification not called on iOS if app is killed - ionic-framework

i am struggling with an issue for weeks now with FCM push notifications on iOS. The problem is that if the app is in killed state when the notification is clicked, the fcm.onNotification callback is not fired.
Checked cases :
iOS - App in foreground - notification popup not shown, correct code running : OK
iOS - App running in background - notification popup shown - notification clicked - correct code running : OK
iOS - App killed by OS / manually swiped away - notification popup shown - notification clicked - app opens - platform.ready runs correctly - onNotification not fired.
On android all is working fine.
I have tried setting everything in the notification i could google up :
force-start : "1"
content_available : true
priority : "high"
click_action : "FCM_PLUGIN_ACTIVITY"
Code which should run :
this.platform.ready().then(() => {
alert("This alert is shown");
this.fcm.onNotification().subscribe(data => {
alert("This alert is not shown");
if (data.wasTapped) {
alert('Received in background');
self.router.navigate([data.landing_page, data.content]);
} else {
alert('Received in foreground');
self.router.navigate([data.landing_page, data.content]);
}
});
});
Thanks!

I made iOS background notifications work with content-available: 1 set in the aps payload and testing in the service whether the additionalData.foreground value is false.

Related

OneSignal - Previously received notification is showing up again when app is opened next time

STR -
when notification receive dismiss from notification panel
close the app and don't use it for some time
open the app again
now will see the previously dismissed notification is showing up again.
shows previous past time of received notification. Example as 5h.
Expected result -
cleared notification from notification panel should not show when the app is opened next time.

Change platform brigtness is triggered when 'Home' is pressed in iOS 15 Simulator

I'm having an issue after my Simulator was updated to iOS 15 in my upcoming Flutter app. When I press the 'Home' button at the top it causes my app to fire the didChangePlatformBrightness() function twice.
Seriously thinking on remove this check while the app is already open and leave it only at startup. Anyone with the same problem and any tips on how to solve it?
On Android everything works fine, just as expected.
I solved this question by monitoring the App lifecycle state. If the app is in resumed state, then I change the color scheme, otherwise I'll do nothing. It occurs because when you press the Home button, the app state changes. See the example below:
void didChangePlatformBrightness() {
if (appState == AppLifecycleState.resumed) {
//give the user a choice for restarting the app, so the colors will
//all be set correctly
showThemeChangeWarning();
setColorScheme();
super.didChangePlatformBrightness();
}
}

display push notification in pretty way in ionic 3

I implemented push notification FCM in my ionic 3 app and I want to display it in pretty way.
for now, I just show alert when get any notification.
I'm looking for another way to display it
ionViewDidLoad() {
FCMPlugin.onNotification(function (data) {
if (data.wasTapped) {
//Notification was received on device tray and tapped by the user.
alert(data.message);
} else {
//Notification was received in foreground. Maybe the user needs to be notified.
alert(data.message);
}
});
FCMPlugin.onTokenRefresh(function (token) {
alert(token);
});
}
You can use local notifications for this. Local notifications are device native and hence will have, as the name suggests, native look and feel.
Refer to https://ionicframework.com/docs/native/local-notifications/ for implementation details.

Ionic cannot navigate to a specific tab upon notification clicked?

I am using Ionic and FCM(firebase) plugin to send push notification. I can receive notifications, when I tap the notification it triggers the alert successfully but it is not navigating to the specified tab. Just to make sure this line:
this.tab.select(2);
works I have tested navigating with that code with a button and it works
FCMPlugin.onNotification(function(data){
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
alert('data was tapped');
this.tab.select(2);
//this.navCtrl.push(ViewurgentnewsPage); also tried this
}else{
//Notification was received in foreground. Maybe the user needs to be notified.
alert('this was received on foreground');
}
});
You should use arrow functions
FCMPlugin.onNotification((data) => {
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
alert('data was tapped');
this.tab.select(2);
} else {
//Notification was received in foreground. Maybe the user needs to be notified.
alert('this was received on foreground');
}
});
By using arrow function, the this keyword still references the component code, where the this.tab property exists.

What is the solution for push notification delegate to fire when app is in not running state?

How can we make fire the push notification delegates if app is not running state without tapping the received notification.
1. Received notification
2.Not tapping on notifications
3.Launching the app by clicking app icon
In this state how can i check if push notification received or not?
See the comment here:
UIApplicationLaunchOptionsRemoteNotificationKey not getting userinfo
Basically set "content-available": 1 in the payload and application:didReceiveRemoteNotification:fetchCompletionHandler will be called.
There is a way, using that you can process your every push notification. add key content-available with value 1 in to your aps dictionary.
so it will look like,
{
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
},
"badge" : 5
"content-available" : 1
}
}
If iOS system detects pushNotification with "content-available" key having value 1, it will call application:didReceiveRemoteNotification:fetchCompletionHandler: of your appDelegate.
Apple - Discussion
Use this method to process incoming remote
notifications for your app. Unlike the
application:didReceiveRemoteNotification: method, which is called only
when your app is running in the foreground, the system calls this
method when your app is running in the foreground or background. In
addition, if you enabled the remote notifications background mode, the
system launches your app (or wakes it from the suspended state) and
puts it in the background state when a remote notification arrives.
However, the system does not automatically launch your app if the user
has force-quit it. In that situation, the user must relaunch your app
or restart the device before the system attempts to launch your app
automatically again.
You need to enable background modes.