diff --git a/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift b/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift index 0495f7de..4e7553a7 100644 --- a/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift +++ b/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift @@ -26,15 +26,15 @@ class AuthenticationService { var needsBiometricAuthenticationToUnlockApp: Bool { let authenticationType = self.authenticationType - return authenticationType == .faceID || authenticationType == .touchID + return authenticationType == .biometric } - + var needsFaceIDToUnlockApp: Bool { - return self.authenticationType == .faceID + return self.needsBiometricAuthenticationToUnlockApp && self.deviceSupportsFaceID } - + var needsTouchIDToUnlockApp: Bool { - return self.authenticationType == .touchID + return self.needsBiometricAuthenticationToUnlockApp && self.deviceSupportsTouchID } var needsPasswordToUnlockApp: Bool { diff --git a/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationType.swift b/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationType.swift index f0cd039e..129a8bd4 100644 --- a/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationType.swift +++ b/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationType.swift @@ -7,8 +7,6 @@ enum AuthenticationType: String { case password - case touchID - - case faceID + case biometric } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift index 43f84104..f27a29ce 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift @@ -14,6 +14,10 @@ struct LoginDialog: View { @State private var enteredPassword: String = "" + private let needsFaceIDToUnlockApp: Bool + + private let needsTouchIDToUnlockApp: Bool + init(_ authenticationService: AuthenticationService = AuthenticationService(), allowCancellingLogin: Bool = false, loginReason: LocalizedStringKey? = nil, loginResult: @escaping (Bool) -> Void) { @@ -22,6 +26,9 @@ struct LoginDialog: View { self.loginReason = loginReason self.loginResult = loginResult + self.needsFaceIDToUnlockApp = authenticationService.needsFaceIDToUnlockApp + self.needsTouchIDToUnlockApp = authenticationService.needsTouchIDToUnlockApp + if authenticationService.needsBiometricAuthenticationToUnlockApp { self.loginWithBiometricAuthentication() } @@ -30,7 +37,7 @@ struct LoginDialog: View { var body: some View { VStack { - if authenticationService.needsFaceIDToUnlockApp { + if needsFaceIDToUnlockApp { VStack { Spacer() @@ -44,7 +51,7 @@ struct LoginDialog: View { Spacer() } } - else if authenticationService.needsTouchIDToUnlockApp { + else if needsTouchIDToUnlockApp { VStack { Spacer() diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift index 967c81bb..fc2bb21d 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift @@ -8,7 +8,7 @@ struct ProtectAppSettingsDialog: View { private let authenticationService = AuthenticationService() - private let supportedAuthenticationTypes: [AuthenticationType] + private var supportedAuthenticationTypes: [AuthenticationType] = [] @State private var isFaceIDSelected: Bool = false @@ -46,11 +46,8 @@ struct ProtectAppSettingsDialog: View { var authenticationTypes = [AuthenticationType]() - if authenticationService.deviceSupportsFaceID { - authenticationTypes.append(.faceID) - } - if authenticationService.deviceSupportsTouchID { - authenticationTypes.append(.touchID) + if authenticationService.deviceSupportsFaceID || authenticationService.deviceSupportsTouchID { + authenticationTypes.append(.biometric) } authenticationTypes.append(.password) @@ -62,12 +59,14 @@ struct ProtectAppSettingsDialog: View { self.supportedAuthenticationTypes = authenticationTypes - if currentAuthenticationType == .faceID || (currentAuthenticationType != .password && authenticationService.deviceSupportsFaceID) { - _isFaceIDSelected = State(initialValue: true) - _selectedAuthenticationTypeIndex = State(initialValue: 0) - } - else if currentAuthenticationType == .touchID || (currentAuthenticationType != .password && authenticationService.deviceSupportsTouchID) { - _isTouchIDSelected = State(initialValue: true) + if currentAuthenticationType == .biometric || currentAuthenticationType != .password { + if authenticationService.deviceSupportsFaceID { + _isFaceIDSelected = State(initialValue: true) + } + else if authenticationService.deviceSupportsTouchID { + _isTouchIDSelected = State(initialValue: true) + } + _selectedAuthenticationTypeIndex = State(initialValue: 0) } else { @@ -147,11 +146,11 @@ struct ProtectAppSettingsDialog: View { isTouchIDSelected = false isPasswordSelected = false isNoAppProtectionSelected = false - - if type == .faceID { + + if authenticationService.needsFaceIDToUnlockApp { isFaceIDSelected = true } - else if type == .touchID { + else if authenticationService.needsTouchIDToUnlockApp { isTouchIDSelected = true } else if type == .password { @@ -193,11 +192,8 @@ struct ProtectAppSettingsDialog: View { } private func setAuthenticationType() { - if isFaceIDSelected { - authenticationService.setAuthenticationType(.faceID) - } - else if isTouchIDSelected { - authenticationService.setAuthenticationType(.touchID) + if isFaceIDSelected || isTouchIDSelected { + authenticationService.setAuthenticationType(.biometric) } else if isPasswordSelected { authenticationService.setAuthenticationTypeToPassword(newPassword)