Merged AuthenticationType touchID and faceID to biometric

This commit is contained in:
dankito 2020-10-02 03:16:46 +02:00
parent 48841b5214
commit 96c842cc89
4 changed files with 31 additions and 30 deletions

View File

@ -26,15 +26,15 @@ class AuthenticationService {
var needsBiometricAuthenticationToUnlockApp: Bool { var needsBiometricAuthenticationToUnlockApp: Bool {
let authenticationType = self.authenticationType let authenticationType = self.authenticationType
return authenticationType == .faceID || authenticationType == .touchID return authenticationType == .biometric
} }
var needsFaceIDToUnlockApp: Bool { var needsFaceIDToUnlockApp: Bool {
return self.authenticationType == .faceID return self.needsBiometricAuthenticationToUnlockApp && self.deviceSupportsFaceID
} }
var needsTouchIDToUnlockApp: Bool { var needsTouchIDToUnlockApp: Bool {
return self.authenticationType == .touchID return self.needsBiometricAuthenticationToUnlockApp && self.deviceSupportsTouchID
} }
var needsPasswordToUnlockApp: Bool { var needsPasswordToUnlockApp: Bool {

View File

@ -7,8 +7,6 @@ enum AuthenticationType: String {
case password case password
case touchID case biometric
case faceID
} }

View File

@ -14,6 +14,10 @@ struct LoginDialog: View {
@State private var enteredPassword: String = "" @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) { 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.loginReason = loginReason
self.loginResult = loginResult self.loginResult = loginResult
self.needsFaceIDToUnlockApp = authenticationService.needsFaceIDToUnlockApp
self.needsTouchIDToUnlockApp = authenticationService.needsTouchIDToUnlockApp
if authenticationService.needsBiometricAuthenticationToUnlockApp { if authenticationService.needsBiometricAuthenticationToUnlockApp {
self.loginWithBiometricAuthentication() self.loginWithBiometricAuthentication()
} }
@ -30,7 +37,7 @@ struct LoginDialog: View {
var body: some View { var body: some View {
VStack { VStack {
if authenticationService.needsFaceIDToUnlockApp { if needsFaceIDToUnlockApp {
VStack { VStack {
Spacer() Spacer()
@ -44,7 +51,7 @@ struct LoginDialog: View {
Spacer() Spacer()
} }
} }
else if authenticationService.needsTouchIDToUnlockApp { else if needsTouchIDToUnlockApp {
VStack { VStack {
Spacer() Spacer()

View File

@ -8,7 +8,7 @@ struct ProtectAppSettingsDialog: View {
private let authenticationService = AuthenticationService() private let authenticationService = AuthenticationService()
private let supportedAuthenticationTypes: [AuthenticationType] private var supportedAuthenticationTypes: [AuthenticationType] = []
@State private var isFaceIDSelected: Bool = false @State private var isFaceIDSelected: Bool = false
@ -46,11 +46,8 @@ struct ProtectAppSettingsDialog: View {
var authenticationTypes = [AuthenticationType]() var authenticationTypes = [AuthenticationType]()
if authenticationService.deviceSupportsFaceID { if authenticationService.deviceSupportsFaceID || authenticationService.deviceSupportsTouchID {
authenticationTypes.append(.faceID) authenticationTypes.append(.biometric)
}
if authenticationService.deviceSupportsTouchID {
authenticationTypes.append(.touchID)
} }
authenticationTypes.append(.password) authenticationTypes.append(.password)
@ -62,12 +59,14 @@ struct ProtectAppSettingsDialog: View {
self.supportedAuthenticationTypes = authenticationTypes self.supportedAuthenticationTypes = authenticationTypes
if currentAuthenticationType == .faceID || (currentAuthenticationType != .password && authenticationService.deviceSupportsFaceID) { if currentAuthenticationType == .biometric || currentAuthenticationType != .password {
_isFaceIDSelected = State(initialValue: true) if authenticationService.deviceSupportsFaceID {
_selectedAuthenticationTypeIndex = State(initialValue: 0) _isFaceIDSelected = State(initialValue: true)
} }
else if currentAuthenticationType == .touchID || (currentAuthenticationType != .password && authenticationService.deviceSupportsTouchID) { else if authenticationService.deviceSupportsTouchID {
_isTouchIDSelected = State(initialValue: true) _isTouchIDSelected = State(initialValue: true)
}
_selectedAuthenticationTypeIndex = State(initialValue: 0) _selectedAuthenticationTypeIndex = State(initialValue: 0)
} }
else { else {
@ -147,11 +146,11 @@ struct ProtectAppSettingsDialog: View {
isTouchIDSelected = false isTouchIDSelected = false
isPasswordSelected = false isPasswordSelected = false
isNoAppProtectionSelected = false isNoAppProtectionSelected = false
if type == .faceID { if authenticationService.needsFaceIDToUnlockApp {
isFaceIDSelected = true isFaceIDSelected = true
} }
else if type == .touchID { else if authenticationService.needsTouchIDToUnlockApp {
isTouchIDSelected = true isTouchIDSelected = true
} }
else if type == .password { else if type == .password {
@ -193,11 +192,8 @@ struct ProtectAppSettingsDialog: View {
} }
private func setAuthenticationType() { private func setAuthenticationType() {
if isFaceIDSelected { if isFaceIDSelected || isTouchIDSelected {
authenticationService.setAuthenticationType(.faceID) authenticationService.setAuthenticationType(.biometric)
}
else if isTouchIDSelected {
authenticationService.setAuthenticationType(.touchID)
} }
else if isPasswordSelected { else if isPasswordSelected {
authenticationService.setAuthenticationTypeToPassword(newPassword) authenticationService.setAuthenticationTypeToPassword(newPassword)