Xamarin Forms Firebase Notifications and receiving in foreground and background

Gordon S 501 Reputation points
2021-08-25T17:16:00.803+00:00

I have an app that is using Firebase for notifications (using CrossGeeks / FirebasePushNotificationPlugin). I have it working so that a "notification" is displayed on the phone whether the app is closed, in the background or the foreground. That was quite a struggle (for me) and it was a few months ago.

I now need to pass data so that I can indicate what type of notification it is. I need the notification to be detected / processed by the app if it (the notification) is touched.

Currently, I send a "notification", can I add "data" to the message which will include the information I need? Or, should I remove the "notification" and add that information to the "data" element?

What do I need in my solution (shared code, Android project, iOS project) in order to handle touched notifications - whether the app is closed, in the background or in the foreground?

I am sending something like this:

{
    "data": {
        "notification_type" : "AuthorisationAccepted",
        "notification_data":""
     },
     "notification": {
       "body" : "hello",
       "title": "firebase",
       "android_channel_id","myNotificationChannel"
     }
 }

Originally, I just had the "notification" part, I added the "data" part to send the other data I require.

The notification appears on the phone but it is not "clickable" - I guess that is the first / main issue. How do I make the notification respond to being touched and cause code to be run in my Android / iOS app, or the shared code would be even better.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,303 questions
{count} votes