-
-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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:
Lines 266 to 274 in 92017ea
| 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:
Lines 320 to 328 in 4629de3
| 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.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request