[英]LABiometryType in iOS11 always return None
我剛剛發現了問題! 你必須調用canEvaluatePolicy
為biometryType
要正確設置。
例:
func isFaceIdSupported() -> Bool {
if #available(iOS 11.0, *){
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
return context.biometryType == LABiometryType.typeFaceID
}
}
return false
}
根據Apple docs for biometryType:
“此屬性僅在canEvaluatePolicy(_:error :)成功生成生物識別策略時設置。默認值為none。”
在這里遇到同樣的問題,用以下代碼修復它。 但它僅適用於Xcode 9.1 Beta(以及模擬器中的iOS 11.1 beta)。
if (laContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: nil)) {
if #available(iOS 11.0, *) {
if (laContext.biometryType == LABiometryType.faceID) {
print("FaceId support")
} else if (laContext.biometryType == LABiometryType.touchID) {
print("TouchId support")
} else {
print("No Biometric support")
}
} else {
// Fallback on earlier versions
}
}
如果使用@Ermish中的代碼,如果設備上沒有注冊的面,則isFaceIdSupported()將返回false。 根據我在iOS SDK 11.1上的最新測試顯示,只需調用laContext.canEvaluatePolicy函數而不關心結果,然后檢查laContext.biometryType的內容。
如果沒有已注冊的面,則canEvaluatePolicy將失敗,但設備支持Face ID。
在Xamarin.iOS中,您需要先評估策略:
NSError error;
bool success = context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out error);
if (context.BiometryType == LABiometryType.TouchId)
{
//Do Something
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.