From 8d035c1d23afd0ffd5a6efb82ab21519cd5cf842 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 11 Jan 2023 14:14:12 +0100 Subject: [PATCH] remove background push and fix push response handling --- sample/Sample.iOS/AppDelegate.cs | 2 +- sample/Sample.iOS/Sample.iOS.csproj | 6 ++++-- sample/Sample/Constants.cs | 2 +- .../NotificationService.cs | 14 +++++++++++--- .../NotifoMobilePushExtensions.ios.cs | 18 +++--------------- .../NotifoMobilePushImplementation.ios.cs | 6 ++++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/sample/Sample.iOS/AppDelegate.cs b/sample/Sample.iOS/AppDelegate.cs index 0155f58..9ab8d74 100644 --- a/sample/Sample.iOS/AppDelegate.cs +++ b/sample/Sample.iOS/AppDelegate.cs @@ -51,7 +51,7 @@ public override void FailedToRegisterForRemoteNotifications(UIApplication applic public override async void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action completionHandler) #pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void { - await NotifoIO.Current.DidReceiveMessageAsync(userInfo); + NotifoIO.Current.DidReceiveMessageAsync(userInfo); completionHandler(UIBackgroundFetchResult.NewData); } diff --git a/sample/Sample.iOS/Sample.iOS.csproj b/sample/Sample.iOS/Sample.iOS.csproj index 5698d71..1bf43f5 100644 --- a/sample/Sample.iOS/Sample.iOS.csproj +++ b/sample/Sample.iOS/Sample.iOS.csproj @@ -48,12 +48,13 @@ 4 ARM64 iPhone Developer - true Entitlements.plist None -all + true + true none @@ -64,8 +65,9 @@ ARM64 iPhone Developer Entitlements.plist - true VS: io.notifo.xamarin.sample Development + false + true ..\..\Notifo.ruleset diff --git a/sample/Sample/Constants.cs b/sample/Sample/Constants.cs index 1c5feb8..29bb9ee 100644 --- a/sample/Sample/Constants.cs +++ b/sample/Sample/Constants.cs @@ -15,6 +15,6 @@ public static class Constants public const string ApiUrl = "https://notifo-dev.easierlife.com"; - public const string UserApiKey = "1zkry2syrttdxjqbs1zoj7dg9o45cixfuxhblhh49lcx"; + public const string UserApiKey = "jp1poshmqt9cadv3znndjm3whrhlqxfdxedwd2snwxyx"; } } diff --git a/sample/SampleNotificationServiceExtension/NotificationService.cs b/sample/SampleNotificationServiceExtension/NotificationService.cs index eefa208..e621e3f 100644 --- a/sample/SampleNotificationServiceExtension/NotificationService.cs +++ b/sample/SampleNotificationServiceExtension/NotificationService.cs @@ -33,17 +33,25 @@ public override async void DidReceiveNotificationRequest(UNNotificationRequest r //Save the notification and create a mutable copy BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy(); - NotifoIO.Current + var notifo = NotifoIO.Current .SetSharedName("group.io.notifo.xamarin.sample") .SetNotificationHandler(new NotificationHandler()); - await NotifoIO.Current.DidReceiveNotificationRequestAsync(request, BestAttemptContent); + notifo.OnLog += On_Log; + + + await NotifoIO.Current.DidReceiveNotificationRequestAsync(request, BestAttemptContent); // Display the notification. ContentHandler(BestAttemptContent); } - public override void TimeWillExpire() + private static void On_Log(object source, NotificationLogEventArgs e) + { + Console.WriteLine($"DEBUG: Log {e.Message} Message Args: {e.MessageArgs}", e.Message, e.MessageArgs); + } + + public override void TimeWillExpire() { // Called just before the extension will be terminated by the system. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. diff --git a/sdk/Notifo.SDK.FirebasePlugin/NotifoMobilePushExtensions.ios.cs b/sdk/Notifo.SDK.FirebasePlugin/NotifoMobilePushExtensions.ios.cs index c5b77bc..5906aec 100644 --- a/sdk/Notifo.SDK.FirebasePlugin/NotifoMobilePushExtensions.ios.cs +++ b/sdk/Notifo.SDK.FirebasePlugin/NotifoMobilePushExtensions.ios.cs @@ -51,22 +51,10 @@ public static INotifoMobilePush UseFirebasePluginEventsProvider(this INotifoMobi /// The instance. /// The notification data dictionary. /// A representing the result of the asynchronous operation. - public static async Task DidReceiveMessageAsync(this INotifoMobilePush notifo, NSDictionary data) + public static void DidReceiveMessageAsync(this INotifoMobilePush notifo, NSDictionary data) { notifo.RaiseDebug(Strings.ReceivedNotification, null, data); - - static bool ContainsPullRefreshRequest(NSDictionary data) - { - var aps = data?.ObjectForKey(new NSString(Constants.ApsKey)) as NSDictionary; - - return aps?.ContainsKey(new NSString(Constants.ContentAvailableKey)) == true; - } - - if (ContainsPullRefreshRequest(data)) - { - await notifo.DidReceivePullRefreshRequestAsync(); - } - + FirebasePushNotificationManager.DidReceiveMessage(data); } @@ -99,7 +87,7 @@ public static void RemoteNotificationRegistrationFailed(this INotifoMobilePush n /// The action to execute when you have finished processing the user's response. public static void DidReceiveNotificationResponse(this INotifoMobilePush notifo, UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { - notifo.DidReceiveNotificationResponse(center, response, completionHandler); + notifo.DidReceiveNotificationResponse(response); if (CrossFirebasePushNotification.Current is IUNUserNotificationCenterDelegate notificationDelegate) { diff --git a/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.ios.cs b/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.ios.cs index 79f7867..b35dd8f 100644 --- a/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.ios.cs +++ b/sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.ios.cs @@ -48,14 +48,16 @@ public async Task DidReceiveNotificationRequestAsync(UNNotificationRequest reque // 3. Enrich with images, which need to be downloaded. await EnrichImagesAsync(content, notification); + await HandlePendingNotificationsAsync(); + // 4. Custom enrichment code (could be potentially be expensive). EnrichWithCustomCode(content, notification); } /// - public async Task DidReceivePullRefreshRequestAsync(PullRefreshOptions? options = null) + public async Task HandlePendingNotificationsAsync() { - options ??= new PullRefreshOptions(); + var options = new PullRefreshOptions(); // iOS does not maintain a queue of undelivered notifications, therefore we have to query here. var notifications = await GetPendingNotificationsAsync(options.Take, options.Period, default);