ios 如何知道是否启用了Face ID

xv8emn3q  于 2023-08-08  发布在  iOS
关注(0)|答案(2)|浏览(165)

首先,为什么每个应用程序都“启用”了Touch ID,而Face ID却没有。因此,如果您设置了Touch ID,则每个应用程序都可以使用它,但Face ID要求用户接受每个应用程序。
如何查找用户是否为我的应用程序启用了Face ID。
这是我用来找出授权类型的代码

let hasAuthenticationBiometrics = myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
    let hasAuthentication = myContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil)

    if #available(iOS 11.0, *) {
        if hasAuthentication {
            if hasAuthenticationBiometrics {
                switch myContext.biometryType {
                case .none: return .none
                case .faceID: return .faceID // Find out if it is enabled
                case .touchID: return .touchID
                }
            } else {
                return .passcode
            }
        } else {
            return .none
        }
    } else {
        if hasAuthentication {
            if hasAuthenticationBiometrics {
                return .touchID
            } else {
                return .passcode
            }
        } else {
            return .none
        }
    }

字符串
如果用户有脸ID,但禁用它为我的应用程序,我总是得到他“有”脸ID,即使我的应用程序是验证密码?

nqwrtyyt

nqwrtyyt1#

找到答案后,使用错误指针找出用户是否禁用了face id。

var error: NSError?
    let hasAuthenticationBiometrics = myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)
    let hasAuthentication = myContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil)

    if #available(iOS 11.0, *) {
        if hasAuthentication {
            if hasAuthenticationBiometrics {
                switch myContext.biometryType {
                case .none: return .none
                case .faceID: return error?.code == -6 ? .passcode : .faceID // If user disabled face id in settings use passcode
                case .touchID: return .touchID
                }
            } else {
                return .passcode
            }
        } else {
            return .none
        }
    }

字符串

9avjhtql

9avjhtql2#

试试下面的代码,使用下面的代码,你可以检查你的应用程序是否支持生物识别

var canEvaluatePolicy: Bool {
var error: NSError?
guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
    print("\(error?.localizedDescription)")
    return false
}
return true

字符串
}

相关问题