From c7e9f30a9a57fc64b700fc26f33ced1eaef2053c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bispo?= Date: Fri, 14 Oct 2022 17:35:17 +0100 Subject: [PATCH] [SG-703] Login request is not removed after dismissing push notification (#2134) * [SG-703] Added category to iOS notifications in order to be able to receive dismiss actions * [SG-703] PR Fix --- src/Core/Constants.cs | 2 ++ src/iOS/Services/iOSPushNotificationService.cs | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Core/Constants.cs b/src/Core/Constants.cs index 903ef5e7e..735c573ae 100644 --- a/src/Core/Constants.cs +++ b/src/Core/Constants.cs @@ -32,6 +32,8 @@ public static string RememberedOrgIdentifierKey = "rememberedOrgIdentifier"; public const string PasswordlessNotificationId = "26072022"; public const string AndroidNotificationChannelId = "general_notification_channel"; + public const string iOSNotificationCategoryId = "dismissableCategory"; + public const string iOSNotificationClearActionId = "Clear"; public const string NotificationData = "notificationData"; public const string NotificationDataType = "Type"; public const int SelectFileRequestCode = 42; diff --git a/src/iOS/Services/iOSPushNotificationService.cs b/src/iOS/Services/iOSPushNotificationService.cs index bcc22b904..aec24657b 100644 --- a/src/iOS/Services/iOSPushNotificationService.cs +++ b/src/iOS/Services/iOSPushNotificationService.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using Bit.App.Abstractions; using Bit.App.Models; +using Bit.App.Resources; using Bit.App.Services; using Bit.Core; using Bit.Core.Services; @@ -84,7 +85,8 @@ namespace Bit.iOS.Services var content = new UNMutableNotificationContent() { Title = title, - Body = message + Body = message, + CategoryIdentifier = Constants.iOSNotificationCategoryId }; if (data != null) @@ -92,6 +94,10 @@ namespace Bit.iOS.Services content.UserInfo = NSDictionary.FromObjectAndKey(NSData.FromString(JsonConvert.SerializeObject(data), NSStringEncoding.UTF8), new NSString(Constants.NotificationData)); } + var actions = new UNNotificationAction[] { UNNotificationAction.FromIdentifier(Constants.iOSNotificationClearActionId, AppResources.Clear, UNNotificationActionOptions.Foreground) }; + var category = UNNotificationCategory.FromIdentifier(Constants.iOSNotificationCategoryId, actions, new string[] { }, UNNotificationCategoryOptions.CustomDismissAction); + UNUserNotificationCenter.Current.SetNotificationCategories(new NSSet(category)); + var request = UNNotificationRequest.FromIdentifier(data.Id, content, null); UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) => {