Xamarin.Forms Push Notifications

Viewed 336

am implementing push notifications to a Xamarin.Forms app. I included this plugin - https://github.com/CrossGeeks/FirebasePushNotificationPlugin. It works great, the only thing that I am missing is getting push notifications when the app is closed (killed).

Started playing with the sample the plugin authors provide (https://github.com/CrossGeeks/FirebasePushNotificationPlugin/tree/master/samples), just needed to add Xamarin.GooglePlayServices.Base nuget package, the rest is almost untouched. I set up the project in Firebase Console and now I can send notifications from Postman, which looks good:

when app is in foreground then the

CrossFirebasePushNotification.Current.OnNotificationReceived

event is properly triggered

when app is backgrounded then the notification is displayed, jingle is played and when I click it, the

CrossFirebasePushNotification.Current.OnNotificationOpened

event is triggered.

So far so good.

But how to show notification when the app is killed? I supposed it should be done by operating system when notification arrives? But obviously I am wrong or I am missing something. If i send a notification from Postman and the app is closed then nothing happens, no notification is displayed and no event is triggered.

There is also following event handler in MainApplication.cs class that looks promissing but it is also triggered only when app is backgrounded.

  //Handle notification when app is closed here
            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
            };

Any ideas how to make this work?

thanks

Jiri

0 Answers
Related