diff --git a/sdk/Notifo.SDK/Extensions/TaskExtensions.cs b/sdk/Notifo.SDK/Extensions/TaskExtensions.cs index 77ad878..862dd1d 100644 --- a/sdk/Notifo.SDK/Extensions/TaskExtensions.cs +++ b/sdk/Notifo.SDK/Extensions/TaskExtensions.cs @@ -13,6 +13,27 @@ namespace Notifo.SDK.Extensions; internal static class TaskExtensions { + private static readonly Action IgnoreTaskContinuation = t => { var ignored = t.Exception; }; + + public static void Forget(this Task task) + { + if (task.IsCompleted) + { +#pragma warning disable IDE0059 // Unnecessary assignment of a value + var ignored = task.Exception; +#pragma warning restore IDE0059 // Unnecessary assignment of a value + } + else + { + task.ContinueWith( + IgnoreTaskContinuation, + CancellationToken.None, + TaskContinuationOptions.OnlyOnFaulted | + TaskContinuationOptions.ExecuteSynchronously, + TaskScheduler.Default); + } + } + public static async Task WithCancellation(this Task task, CancellationToken cancellationToken) { var tcs = new TaskCompletionSource(); diff --git a/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.android.cs b/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.android.cs index e786d09..7a91455 100644 --- a/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.android.cs +++ b/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.android.cs @@ -28,14 +28,6 @@ partial void SetupPlatform() OnNotificationReceived += PushEventsProvider_OnNotificationReceivedAndroid; } - private void PushEventsProvider_OnNotificationReceivedAndroid(object sender, NotificationEventArgs e) - { - if (!string.IsNullOrWhiteSpace(e.Notification.TrackSeenUrl)) - { - _ = TrackNotificationsAsync(e.Notification); - } - } - /// public INotifoMobilePush SetNotificationHandler(INotificationHandler? notificationHandler) { @@ -50,6 +42,11 @@ public INotifoMobilePush SetImageCacheCapacity(int capacity) return this; } + private void PushEventsProvider_OnNotificationReceivedAndroid(object sender, NotificationEventArgs e) + { + TrackNotificationsAsync(e.Notification).Forget(); + } + /// public async Task OnBuildNotificationAsync(NotificationCompat.Builder notificationBuilder, UserNotificationDto notification) { diff --git a/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.cs b/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.cs index 92c8e63..22b51e3 100644 --- a/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.cs +++ b/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using Notifo.SDK.CommandQueue; +using Notifo.SDK.Extensions; using Notifo.SDK.Helpers; using Notifo.SDK.PushEventProvider; using Notifo.SDK.Resources; @@ -196,7 +197,7 @@ async Task RegisterAsync() Register(tokenToRegister); } - _ = RegisterAsync(); + RegisterAsync().Forget(); } /// diff --git a/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.ios.cs b/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.ios.cs index 54fab0b..a90de01 100644 --- a/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.ios.cs +++ b/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.ios.cs @@ -58,6 +58,8 @@ public async Task DidReceivePullRefreshRequestAsync() // iOS does not maintain a queue of undelivered notifications, therefore we have to query here. var notifications = await GetPendingNotificationsAsync(refreshOptions.Take, refreshOptions.Period, default); + List? trackImmediatly = null; + foreach (var notification in notifications) { if (refreshOptions.RaiseEvent) @@ -67,13 +69,18 @@ public async Task DidReceivePullRefreshRequestAsync() if (notification.Silent || !refreshOptions.PresentNotification) { + trackImmediatly ??= new List(); + trackImmediatly.Add(notification); continue; } await ShowLocalNotificationAsync(notification); } - await TrackNotificationsAsync(notifications.ToArray()); + if (trackImmediatly != null) + { + await TrackNotificationsAsync(trackImmediatly.ToArray()); + } } private async Task> GetPendingNotificationsAsync(int take, TimeSpan maxAge, @@ -160,6 +167,10 @@ private async Task ShowLocalNotificationAsync(UserNotificationDto notification) { NotifoIO.Current.RaiseError(error.LocalizedDescription, null, this); } + else + { + TrackNotificationsAsync(notification).Forget(); + } }); }