Merged AuthenticationType touchID and faceID to biometric
This commit is contained in:
parent
48841b5214
commit
96c842cc89
|
@ -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 {
|
||||
|
|
|
@ -7,8 +7,6 @@ enum AuthenticationType: String {
|
|||
|
||||
case password
|
||||
|
||||
case touchID
|
||||
|
||||
case faceID
|
||||
case biometric
|
||||
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue