有沒有辦法檢測用戶在使用“LAContext().evaluatePolicy(.deviceOwnerAuthentication, localizedReason: someReason)”后是否拒絕了生物識別(faceID)?
例如,
- 用戶首次登錄時,系統會提示他們應用程式是否可以使用他們的生物識別技術
- 用戶拒絕生物識別,然后提示輸入密碼
- 用戶拒絕密碼
似乎 canEvaluatePolicy 為“LAContext().canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)”回傳 true,直到我關閉并重新打開應用程式。
我希望能夠提醒用戶他們可以在他們的應用設定中打開 faceID。
uj5u.com熱心網友回復:
// Declare You're own Error type to handle possible errors
enum BiometryError: Swift.Error, LocalizedError {
case unavailable, // Biometry unavailable
failed, // Can't verify
cancel, // User pressed cancel
failback, // User choose password
locked, // Biometry is locked
enrolled, // Biometry not setup
succsess // Success
init(error: LAError) {
switch error {
case LAError.authenticationFailed:
self = .failed
case LAError.userCancel:
self = .cancel
case LAError.userFallback:
self = .failback
case LAError.biometryNotAvailable:
self = .unavailable
case LAError.biometryNotEnrolled:
self = .enrolled
case LAError.biometryLockout:
self = .locked
default:
self = .unavailable
}
}
public var errorDescription: String? {
switch self {
case .unavailable:
return "Unavailable"
case .failed:
return "Failed"
case .cancel:
return "Cancel"
case .failback:
return "Failback"
case .locked:
return "Locked"
case .enrolled:
return "Enrolled"
case .succsess:
return "Succsess"
}
}
}
// Authenticate method
func authenticateBiometry(reply callback: @escaping (Bool, BiometryError?) -> Void) {
LAContext().evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "reason") { success, error in
if let error = error as? LAError, !success {
// Here in this callback You can handle error and show alert if You want
callback(false, BiometryError(error: error))
} else {
// Success
callback(true, nil)
}
}
}
uj5u.com熱心網友回復:
似乎沒有辦法確定您在問題中描述的案例。
我注意到canEvaluatePolicy狀態檔案:
不要存盤此方法的回傳值,因為它可能會因系統更改而更改。例如,用戶可能會在您呼叫此方法后禁用 Touch ID。但是,報告的值會保持一致,直到您的應用程式進入后臺。
但是,在測驗中似乎即使將應用程式置于后臺也不會更改canEvaluatePolicy.
正如您在問題中所指出的,在重新啟動應用程式之前,回傳的值不會更改。您還將看到,如果您進入首選項并切換應用的生物識別設定,那么您的應用實際上會重新啟動。其他與隱私相關的設定也會發生同樣的程序。
如果您確定它已被拒絕,您可以在后續啟動時提供生物識別身份驗證,但您應該警惕在用戶已經做出決定時竊聽他們。
您可以使用的另一種方法是嘗試LAContext().evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "reason"),如果由于生物識別技術被拒絕而失敗,請重試身份驗證,LAContext().evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "reason")這將立即提示輸入密碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/336400.html
上一篇:統計用戶瀏覽量(SwiftUI)
下一篇:SafariiOS15視頻問題
