Biometry Type when user denied biometry usage

…衆ロ難τιáo~ 提交于 2019-12-05 15:05:32

I've got the same identical issue, and I've just found out that if you evaluate against the key LAPolicyDeviceOwnerAuthentication instead of LAPolicyDeviceOwnerAuthenticationWithBiometrics, even after the user declined the permission, the evaluation succeeds and you get the correct biometryType. Your code would be like

static fileprivate var biometryType: DSLocalAuthenticationBiometryType {
    let context = LAContext()

    var error: NSError?
    let _ = context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)

    if #available(iOS 11.0, *) {

        return context.biometryType == .typeFaceID ? .typeFaceID : .none
    }
    else {
        return .none
    }
}

NOTE: on devices without touch id and face id, it still returning YES, so you would not know whether the device really has a biometric hw or not with iOS lower than 11 (which do not expose the property biometriyType)

Update

For devices with iOS version 10 or lower, you can use the LAPolicyDeviceOwnerAuthenticationWithBiometrics as usual, it will behave correctly (returning true whether the device supports the touch Id), so it's just a matter of differentiating the running OS version :)

Let me know if it works :)

Best

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!