Skip to content

Commit 4629de3

Browse files
Merge pull request #80 from thomasgalliker/foreground-handling-notification-actions
Merge foreground-handling-notification-actions into develop
2 parents 9bd92a7 + 6ce79aa commit 4629de3

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

Plugin.FirebasePushNotifications/Platforms/Android/NotificationBuilder.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,7 @@ public virtual bool ShouldHandleNotificationReceived(IDictionary<string, object>
3939
// we don't display any local notification.
4040
return false;
4141
}
42-
43-
if (data.ContainsKey(Constants.ClickActionKey) ||
44-
data.ContainsKey(Constants.CategoryKey) ||
45-
data.ContainsKey(Constants.GcmNotificationClickActionKey))
46-
{
47-
// If we received a "click_action" or "category"
48-
// we need to show a local notification with action buttons.
49-
return true;
50-
}
51-
42+
5243
var notificationImportance = this.GetNotificationImportance(data);
5344
if (notificationImportance >= NotificationImportance.High)
5445
{
@@ -57,6 +48,20 @@ public virtual bool ShouldHandleNotificationReceived(IDictionary<string, object>
5748
return true;
5849
}
5950

51+
if (data.ContainsKey(Constants.ClickActionKey) ||
52+
data.ContainsKey(Constants.CategoryKey) ||
53+
data.ContainsKey(Constants.GcmNotificationClickActionKey))
54+
{
55+
var isInForeground = IsInForeground();
56+
if (isInForeground == false)
57+
{
58+
// If we received a "click_action" or "category"
59+
// and we run in background mode
60+
// we need to show a local notification with action buttons.
61+
return true;
62+
}
63+
}
64+
6065
var notificationChannel = GetChannel(data);
6166
if (notificationChannel is { Importance: >= NotificationImportance.High })
6267
{
@@ -73,12 +78,6 @@ public virtual bool ShouldHandleNotificationReceived(IDictionary<string, object>
7378
return true;
7479
}
7580

76-
//var isInForeground = IsInForeground();
77-
//if (isInForeground == false)
78-
//{
79-
// // There is currently no special handling for apps that run in background mode
80-
//}
81-
8281
return false;
8382
}
8483

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
namespace Plugin.FirebasePushNotifications
3+
{
4+
internal static partial class Constants
5+
{
6+
internal const string ApsPriorityKey = "aps.priority";
7+
}
8+
}

Plugin.FirebasePushNotifications/Platforms/iOS/FirebasePushNotificationManager.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ private static UNNotificationPresentationOptions GetNotificationPresentationOpti
335335
{
336336
var notificationPresentationOptions = defaultNotificationPresentationOptions;
337337

338-
if (data.TryGetValue(Constants.PriorityKey, out var p) && $"{p}".ToLower() is string priority)
338+
var priority = GetPriorityValue(data);
339+
if (!string.IsNullOrEmpty(priority))
339340
{
340341
if (priority is "high" or "max")
341342
{
@@ -386,6 +387,23 @@ private static UNNotificationPresentationOptions GetNotificationPresentationOpti
386387
return notificationPresentationOptions;
387388
}
388389

390+
private static string GetPriorityValue(IDictionary<string,object> data)
391+
{
392+
if (data.TryGetString(Constants.PriorityKey, out var priorityValue))
393+
{
394+
}
395+
else if (data.TryGetString(Constants.ApsPriorityKey, out priorityValue))
396+
{
397+
}
398+
399+
if (!string.IsNullOrEmpty(priorityValue))
400+
{
401+
return priorityValue.ToLowerInvariant();
402+
}
403+
404+
return null;
405+
}
406+
389407
/// <inheritdoc />
390408
public void SubscribeTopics(string[] topics)
391409
{

0 commit comments

Comments
 (0)