[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
This commit is contained in:
André Bispo 2022-10-14 17:35:17 +01:00 committed by GitHub
parent 6c404c8229
commit c7e9f30a9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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;

View File

@ -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<UNNotificationCategory>(category));
var request = UNNotificationRequest.FromIdentifier(data.Id, content, null);
UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) =>
{