Summary
Currently using the NotificationReceived event, only on Android, we can change the behavior of the push notification before it is processed simply modifying the Data dictionary in the FirebasePushNotificationDataEventArgs received.
This request allows also iOS to customize the push notification.
API Changes
No API changes are required, the workaround is to move a simple line of code a couple of rows earlier.
We are using the v2.5.13, so supposing it is the main branch, moving the line 273 after the 267 here:
|
|
|
var data = notification.Request.Content.UserInfo.GetParameters(); |
|
var notificationPresentationOptions = GetNotificationPresentationOptions(data); |
|
this.logger.LogDebug( |
|
$"WillPresentNotification: UNNotification.Request.Identifier \"{notification.Request.Identifier}\", " + |
|
$"UNNotificationPresentationOptions={notificationPresentationOptions}"); |
|
|
|
this.HandleNotificationReceived(data); |
|
|
allows the
notificationPresentationOptions to be filled based on the Data modified by the
NotificationReceived event, as a consequence this allows us to customize the push notification, exactly as in Android, before it is handled or created.
The same can be achieved for the develop branch here:
|
|
|
var data = notification.Request.Content.UserInfo.GetParameters(); |
|
var notificationPresentationOptions = GetNotificationPresentationOptions(data, this.options.iOS.PresentationOptions); |
|
this.logger.LogDebug( |
|
$"WillPresentNotification: UNNotification.Request.Identifier \"{notification.Request.Identifier}\", " + |
|
$"UNNotificationPresentationOptions={notificationPresentationOptions}"); |
|
|
|
this.HandleNotificationReceived(data); |
|
|
Moving the line 327 after the 321.
Intended Use Case
With this modification we can use code like this:
_firebasePushNotification.NotificationReceived += (s, e) =>
{
// Event "NotificationReceived" (with app in foreground)
_logger.LogDebug("Firebase-NotificationReceived - Data: {data}", e.Data);
#if ANDROID || IOS
// Force the high priority when the app is in foreground to show the notification as badge
var _isInBackground = ((App)(App.Current!)).IsInBackground;
if (!_isInBackground && !e.Data.ContainsKey("priority")) e.Data.Add("priority", "high");
#endif
};
Which works on both, Android and iOS.
Summary
Currently using the
NotificationReceivedevent, only on Android, we can change the behavior of the push notification before it is processed simply modifying theDatadictionary in theFirebasePushNotificationDataEventArgsreceived.This request allows also iOS to customize the push notification.
API Changes
No API changes are required, the workaround is to move a simple line of code a couple of rows earlier.
We are using the v2.5.13, so supposing it is the
mainbranch, moving the line 273 after the 267 here:Plugin.FirebasePushNotifications/Plugin.FirebasePushNotifications/Platforms/iOS/FirebasePushNotificationManager.cs
Lines 266 to 274 in 92017ea
allows the
notificationPresentationOptionsto be filled based on the Data modified by theNotificationReceivedevent, as a consequence this allows us to customize the push notification, exactly as in Android, before it is handled or created.The same can be achieved for the
developbranch here:Plugin.FirebasePushNotifications/Plugin.FirebasePushNotifications/Platforms/iOS/FirebasePushNotificationManager.cs
Lines 320 to 328 in 4629de3
Moving the line 327 after the 321.
Intended Use Case
With this modification we can use code like this:
Which works on both, Android and iOS.