50 lines
1.9 KiB
Swift
50 lines
1.9 KiB
Swift
//
|
|
// ActionSetupBiometricsHandler.swift
|
|
// MobileFirstFramework
|
|
//
|
|
// Created by Scott Pfeil on 4/5/23.
|
|
// Copyright © 2023 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import MVMCore
|
|
import LocalAuthentication
|
|
|
|
open class ActionBiometricStateHandler: MVMCoreActionHandlerProtocol {
|
|
|
|
enum Error: MVMError, CustomStringConvertible {
|
|
case unknown
|
|
|
|
public var description: String {
|
|
switch self {
|
|
case .unknown:
|
|
return "Cannot evaluate biometric policy for an unknown reason."
|
|
}
|
|
}
|
|
}
|
|
|
|
required public init() {}
|
|
|
|
public func execute(with model: MVMCore.ActionModelProtocol, delegateObject: MVMCore.DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
|
|
guard let model = model as? ActionBiometricStateModel else { return }
|
|
|
|
var error: NSError?
|
|
let context = LAContext()
|
|
guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
|
|
guard let error = error else {
|
|
throw Self.Error.unknown
|
|
}
|
|
if error.code == LAError.biometryNotEnrolled.rawValue,
|
|
let action = model.biometricsDisabledAction {
|
|
try await delegateObject?.actionDelegate?.action(with: action, additionalData: additionalData, delegateObject: delegateObject)
|
|
} else if error.code == LAError.biometryNotAvailable.rawValue,
|
|
let action = model.biometricsDeniedAction {
|
|
try await delegateObject?.actionDelegate?.action(with: action, additionalData: additionalData, delegateObject: delegateObject)
|
|
} else {
|
|
throw error
|
|
}
|
|
return
|
|
}
|
|
try await delegateObject?.actionDelegate?.action(with: model.biometricsEnabledAction, additionalData: additionalData, delegateObject: delegateObject)
|
|
}
|
|
}
|