diff --git a/src/App/Pages/Vault/AddEditPageViewModel.cs b/src/App/Pages/Vault/AddEditPageViewModel.cs index 1dd4a988b..cf3977a25 100644 --- a/src/App/Pages/Vault/AddEditPageViewModel.cs +++ b/src/App/Pages/Vault/AddEditPageViewModel.cs @@ -428,7 +428,7 @@ namespace Bit.App.Pages await _deviceActionService.HideLoadingAsync(); _platformUtilsService.ShowToast("success", null, EditMode ? AppResources.ItemUpdated : AppResources.NewItemCreated); - _messagingService.Send(EditMode ? "editedCipher" : "addedCipher"); + _messagingService.Send(EditMode ? "editedCipher" : "addedCipher", Cipher.Id); if((Page as AddEditPage).FromAutofillFramework) { @@ -469,7 +469,7 @@ namespace Bit.App.Pages await _cipherService.DeleteWithServerAsync(Cipher.Id); await _deviceActionService.HideLoadingAsync(); _platformUtilsService.ShowToast("success", null, AppResources.ItemDeleted); - _messagingService.Send("deletedCipher"); + _messagingService.Send("deletedCipher", Cipher); return true; } catch(ApiException e) diff --git a/src/App/Pages/Vault/ViewPageViewModel.cs b/src/App/Pages/Vault/ViewPageViewModel.cs index 548882a1b..b898b5e1c 100644 --- a/src/App/Pages/Vault/ViewPageViewModel.cs +++ b/src/App/Pages/Vault/ViewPageViewModel.cs @@ -275,7 +275,7 @@ namespace Bit.App.Pages await _cipherService.DeleteWithServerAsync(Cipher.Id); await _deviceActionService.HideLoadingAsync(); _platformUtilsService.ShowToast("success", null, AppResources.ItemDeleted); - _messagingService.Send("deletedCipher"); + _messagingService.Send("deletedCipher", Cipher); return true; } catch(ApiException e) diff --git a/src/iOS.Core/Controllers/LoginAddViewController.cs b/src/iOS.Core/Controllers/LoginAddViewController.cs index 707039175..b21083e93 100644 --- a/src/iOS.Core/Controllers/LoginAddViewController.cs +++ b/src/iOS.Core/Controllers/LoginAddViewController.cs @@ -175,7 +175,7 @@ namespace Bit.iOS.Core.Controllers await loadingAlert.DismissViewControllerAsync(true); if(await ASHelpers.IdentitiesCanIncremental()) { - var identity = await ASHelpers.GetCipherIdentityAsync(cipherDomain.Id, _cipherService); + var identity = await ASHelpers.GetCipherIdentityAsync(cipherDomain.Id); if(identity != null) { await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync( @@ -184,7 +184,7 @@ namespace Bit.iOS.Core.Controllers } else { - await ASHelpers.ReplaceAllIdentities(_cipherService); + await ASHelpers.ReplaceAllIdentities(); } Success(); } diff --git a/src/iOS.Core/Utilities/ASHelpers.cs b/src/iOS.Core/Utilities/ASHelpers.cs index d6f2b5466..9fceec5e7 100644 --- a/src/iOS.Core/Utilities/ASHelpers.cs +++ b/src/iOS.Core/Utilities/ASHelpers.cs @@ -4,13 +4,15 @@ using System.Threading.Tasks; using AuthenticationServices; using Bit.Core.Abstractions; using Bit.Core.Models.View; +using Bit.Core.Utilities; namespace Bit.iOS.Core.Utilities { public static class ASHelpers { - public static async Task ReplaceAllIdentities(ICipherService cipherService) + public static async Task ReplaceAllIdentities() { + var cipherService = ServiceContainer.Resolve("cipherService"); if(await AutofillEnabled()) { var identities = new List(); @@ -42,8 +44,9 @@ namespace Bit.iOS.Core.Utilities return state != null && state.Enabled; } - public static async Task GetCipherIdentityAsync(string cipherId, ICipherService cipherService) + public static async Task GetCipherIdentityAsync(string cipherId) { + var cipherService = ServiceContainer.Resolve("cipherService"); var cipher = await cipherService.GetAsync(cipherId); if(cipher == null) { diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index 93c01acda..739c968f0 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; +using AuthenticationServices; using Bit.App.Abstractions; using Bit.App.Resources; using Bit.App.Services; @@ -51,7 +52,7 @@ namespace Bit.iOS AppearanceAdjustments(); ZXing.Net.Mobile.Forms.iOS.Platform.Init(); - _broadcasterService.Subscribe(nameof(AppDelegate), (message) => + _broadcasterService.Subscribe(nameof(AppDelegate), async (message) => { if(message.Command == "scheduleLockTimer") { @@ -87,23 +88,59 @@ namespace Bit.iOS if(message.Data is Dictionary data && data.ContainsKey("successfully")) { var success = data["successfully"] as bool?; - if(success.GetValueOrDefault()) + if(success.GetValueOrDefault() && _deviceActionService.SystemMajorVersion() >= 12) { - + await ASHelpers.ReplaceAllIdentities(); } } } else if(message.Command == "addedCipher" || message.Command == "editedCipher") { - + if(_deviceActionService.SystemMajorVersion() >= 12) + { + if(await ASHelpers.IdentitiesCanIncremental()) + { + var cipherId = message.Data as string; + if(message.Command == "addedCipher" && !string.IsNullOrWhiteSpace(cipherId)) + { + var identity = await ASHelpers.GetCipherIdentityAsync(cipherId); + if(identity == null) + { + return; + } + await ASCredentialIdentityStore.SharedStore?.SaveCredentialIdentitiesAsync( + new ASPasswordCredentialIdentity[] { identity }); + return; + } + } + await ASHelpers.ReplaceAllIdentities(); + } } else if(message.Command == "deletedCipher") { - + if(_deviceActionService.SystemMajorVersion() >= 12) + { + if(await ASHelpers.IdentitiesCanIncremental()) + { + var identity = ASHelpers.ToCredentialIdentity( + message.Data as Bit.Core.Models.View.CipherView); + if(identity == null) + { + return; + } + await ASCredentialIdentityStore.SharedStore?.RemoveCredentialIdentitiesAsync( + new ASPasswordCredentialIdentity[] { identity }); + return; + } + await ASHelpers.ReplaceAllIdentities(); + } } else if(message.Command == "loggedOut") { - + if(_deviceActionService.SystemMajorVersion() >= 12) + { + await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync(); + } } });