public override bool FinishedLaunching(UIApplication app, NSDictionary options) { Forms.Init(); if (!Resolver.IsSet) { SetIoc(); } _lockService = Resolver.Resolve <ILockService>(); _deviceInfoService = Resolver.Resolve <IDeviceInfoService>(); _cipherService = Resolver.Resolve <ICipherService>(); _pushHandler = new iOSPushNotificationHandler(Resolver.Resolve <IPushNotificationListener>()); _nfcDelegate = new NFCReaderDelegate((success, message) => ProcessYubikey(success, message)); var appIdService = Resolver.Resolve <IAppIdService>(); var crashManagerDelegate = new HockeyAppCrashManagerDelegate( appIdService, Resolver.Resolve <IAuthService>()); var manager = BITHockeyManager.SharedHockeyManager; manager.Configure("51f96ae568ba45f699a18ad9f63046c3", crashManagerDelegate); manager.CrashManager.CrashManagerStatus = BITCrashManagerStatus.AutoSend; manager.UserId = appIdService.AppId; manager.StartManager(); manager.Authenticator.AuthenticateInstallation(); manager.DisableMetricsManager = manager.DisableFeedbackManager = manager.DisableUpdateManager = true; LoadApplication(new App.App( null, Resolver.Resolve <IAuthService>(), Resolver.Resolve <IConnectivity>(), Resolver.Resolve <IDatabaseService>(), Resolver.Resolve <ISyncService>(), Resolver.Resolve <ISettings>(), _lockService, Resolver.Resolve <ILocalizeService>(), Resolver.Resolve <IAppInfoService>(), Resolver.Resolve <IAppSettingsService>(), Resolver.Resolve <IDeviceActionService>())); // Appearance stuff var primaryColor = new UIColor(red: 0.24f, green: 0.55f, blue: 0.74f, alpha: 1.0f); var grayLight = new UIColor(red: 0.47f, green: 0.47f, blue: 0.47f, alpha: 1.0f); UINavigationBar.Appearance.ShadowImage = new UIImage(); UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default); UIBarButtonItem.AppearanceWhenContainedIn(new Type[] { typeof(UISearchBar) }).TintColor = primaryColor; UIButton.AppearanceWhenContainedIn(new Type[] { typeof(UISearchBar) }).SetTitleColor(primaryColor, UIControlState.Normal); UIButton.AppearanceWhenContainedIn(new Type[] { typeof(UISearchBar) }).TintColor = primaryColor; UIStepper.Appearance.TintColor = grayLight; UISlider.Appearance.TintColor = primaryColor; MessagingCenter.Subscribe <Xamarin.Forms.Application, ToolsExtensionPage>( Xamarin.Forms.Application.Current, "ShowAppExtension", (sender, page) => { var itemProvider = new NSItemProvider(new NSDictionary(), Core.Constants.UTTypeAppExtensionSetup); var extensionItem = new NSExtensionItem(); extensionItem.Attachments = new NSItemProvider[] { itemProvider }; var activityViewController = new UIActivityViewController(new NSExtensionItem[] { extensionItem }, null); activityViewController.CompletionHandler = (activityType, completed) => { page.EnabledExtension(completed && activityType == "com.8bit.bitwarden.find-login-action-extension"); }; var modal = UIApplication.SharedApplication.KeyWindow.RootViewController.ModalViewController; if (activityViewController.PopoverPresentationController != null) { activityViewController.PopoverPresentationController.SourceView = modal.View; var frame = UIScreen.MainScreen.Bounds; frame.Height /= 2; activityViewController.PopoverPresentationController.SourceRect = frame; } modal.PresentViewController(activityViewController, true, null); }); MessagingCenter.Subscribe <Xamarin.Forms.Application, bool>( Xamarin.Forms.Application.Current, "ListenYubiKeyOTP", (sender, listen) => { if (_deviceInfoService.NfcEnabled) { _nfcSession?.InvalidateSession(); _nfcSession?.Dispose(); _nfcSession = null; if (listen) { _nfcSession = new NFCNdefReaderSession(_nfcDelegate, null, true); _nfcSession.AlertMessage = AppResources.HoldYubikeyNearTop; _nfcSession.BeginSession(); } } }); UIApplication.SharedApplication.StatusBarHidden = false; UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; MessagingCenter.Subscribe <Xamarin.Forms.Application, bool>( Xamarin.Forms.Application.Current, "ShowStatusBar", (sender, show) => { UIApplication.SharedApplication.SetStatusBarHidden(!show, false); }); MessagingCenter.Subscribe <Xamarin.Forms.Application, bool>( Xamarin.Forms.Application.Current, "FullSyncCompleted", async(sender, successfully) => { if (_deviceInfoService.Version >= 12 && successfully) { await ASHelpers.ReplaceAllIdentities(_cipherService); } }); MessagingCenter.Subscribe <Xamarin.Forms.Application, Tuple <string, bool> >( Xamarin.Forms.Application.Current, "UpsertedCipher", async(sender, data) => { if (_deviceInfoService.Version >= 12) { if (await ASHelpers.IdentitiesCanIncremental()) { if (data.Item2) { var identity = await ASHelpers.GetCipherIdentityAsync(data.Item1, _cipherService); if (identity == null) { return; } await ASCredentialIdentityStore.SharedStore?.SaveCredentialIdentitiesAsync( new ASPasswordCredentialIdentity[] { identity }); return; } } await ASHelpers.ReplaceAllIdentities(_cipherService); } }); MessagingCenter.Subscribe <Xamarin.Forms.Application, Cipher>( Xamarin.Forms.Application.Current, "DeletedCipher", async(sender, cipher) => { if (_deviceInfoService.Version >= 12) { if (await ASHelpers.IdentitiesCanIncremental()) { var identity = ASHelpers.ToCredentialIdentity(cipher); if (identity == null) { return; } await ASCredentialIdentityStore.SharedStore?.RemoveCredentialIdentitiesAsync( new ASPasswordCredentialIdentity[] { identity }); return; } await ASHelpers.ReplaceAllIdentities(_cipherService); } }); MessagingCenter.Subscribe <Xamarin.Forms.Application>( Xamarin.Forms.Application.Current, "LoggedOut", async(sender) => { if (_deviceInfoService.Version >= 12) { await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync(); } }); ZXing.Net.Mobile.Forms.iOS.Platform.Init(); return(base.FinishedLaunching(app, options)); }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { Forms.Init(); InitApp(); _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService"); _messagingService = ServiceContainer.Resolve <IMessagingService>("messagingService"); _broadcasterService = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService"); _storageService = ServiceContainer.Resolve <IStorageService>("storageService"); _stateService = ServiceContainer.Resolve <IStateService>("stateService"); _eventService = ServiceContainer.Resolve <IEventService>("eventService"); LoadApplication(new App.App(null)); iOSCoreHelpers.AppearanceAdjustments(); ZXing.Net.Mobile.Forms.iOS.Platform.Init(); _broadcasterService.Subscribe(nameof(AppDelegate), async(message) => { try { if (message.Command == "startEventTimer") { StartEventTimer(); } else if (message.Command == "stopEventTimer") { var task = StopEventTimerAsync(); } else if (message.Command == "updatedTheme") { Device.BeginInvokeOnMainThread(() => { iOSCoreHelpers.AppearanceAdjustments(); }); } else if (message.Command == "listenYubiKeyOTP") { iOSCoreHelpers.ListenYubiKey((bool)message.Data, _deviceActionService, _nfcSession, _nfcDelegate); } else if (message.Command == "unlocked") { var needsAutofillReplacement = await _storageService.GetAsync <bool?>( Core.Constants.AutofillNeedsIdentityReplacementKey); if (needsAutofillReplacement.GetValueOrDefault()) { await ASHelpers.ReplaceAllIdentities(); } } else if (message.Command == "showAppExtension") { Device.BeginInvokeOnMainThread(() => ShowAppExtension((ExtensionPageViewModel)message.Data)); } else if (message.Command == "syncCompleted") { if (message.Data is Dictionary <string, object> data && data.ContainsKey("successfully")) { var success = data["successfully"] as bool?; if (success.GetValueOrDefault() && _deviceActionService.SystemMajorVersion() >= 12) { await ASHelpers.ReplaceAllIdentities(); } } } else if (message.Command == "addedCipher" || message.Command == "editedCipher" || message.Command == "restoredCipher") { 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" || message.Command == "softDeletedCipher") { 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 == "logout") { if (_deviceActionService.SystemMajorVersion() >= 12) { await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync(); } } else if ((message.Command == "softDeletedCipher" || message.Command == "restoredCipher") && _deviceActionService.SystemMajorVersion() >= 12) { await ASHelpers.ReplaceAllIdentities(); } else if (message.Command == "vaultTimeoutActionChanged") { var timeoutAction = await _stateService.GetVaultTimeoutActionAsync(); if (timeoutAction == VaultTimeoutAction.Logout) { await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync(); } else { await ASHelpers.ReplaceAllIdentities(); } } } catch (Exception ex) { LoggerHelper.LogEvenIfCantBeResolved(ex); } }); return(base.FinishedLaunching(app, options)); }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { Forms.Init(); InitApp(); _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService"); _messagingService = ServiceContainer.Resolve <IMessagingService>("messagingService"); _broadcasterService = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService"); _storageService = ServiceContainer.Resolve <IStorageService>("storageService"); _lockService = ServiceContainer.Resolve <ILockService>("lockService"); _eventService = ServiceContainer.Resolve <IEventService>("eventService"); _platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService"); _cozyClientService = ServiceContainer.Resolve <ICozyClientService>("cozyClientService"); LoadApplication(new App.App(null)); iOSCoreHelpers.AppearanceAdjustments(_deviceActionService); ZXing.Net.Mobile.Forms.iOS.Platform.Init(); _broadcasterService.Subscribe(nameof(AppDelegate), async(message) => { if (message.Command == "scheduleLockTimer") { LockTimer((int)message.Data); } else if (message.Command == "cancelLockTimer") { CancelLockTimer(); } else if (message.Command == "startEventTimer") { StartEventTimer(); } else if (message.Command == "stopEventTimer") { var task = StopEventTimerAsync(); } else if (message.Command == "updatedTheme") { // ThemeManager.SetThemeStyle(message.Data as string); } else if (message.Command == "copiedToClipboard") { Device.BeginInvokeOnMainThread(() => { var task = ClearClipboardTimerAsync(message.Data as Tuple <string, int?, bool>); }); } else if (message.Command == "listenYubiKeyOTP") { ListenYubiKey((bool)message.Data); } else if (message.Command == "unlocked") { var needsAutofillReplacement = await _storageService.GetAsync <bool?>( Core.Constants.AutofillNeedsIdentityReplacementKey); if (needsAutofillReplacement.GetValueOrDefault()) { await ASHelpers.ReplaceAllIdentities(); } } else if (message.Command == "showAppExtension") { Device.BeginInvokeOnMainThread(() => ShowAppExtension((ExtensionPageViewModel)message.Data)); } else if (message.Command == "showStatusBar") { Device.BeginInvokeOnMainThread(() => UIApplication.SharedApplication.SetStatusBarHidden(!(bool)message.Data, false)); } else if (message.Command == "syncCompleted") { if (message.Data is Dictionary <string, object> data && data.ContainsKey("successfully")) { var success = data["successfully"] as bool?; 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(); } } }); return(base.FinishedLaunching(app, options)); }