iOS8 check if device has Touch ID

后端 未结 5 623
不思量自难忘°
不思量自难忘° 2021-02-12 23:50

LAContext has method to check if device can evaluate touch ID and gives error message. Problem is that same error message \"LAErrorPasscodeNotSet\" is given by system in two cas

5条回答
  •  情歌与酒
    2021-02-13 00:14

    In Swift 3

    fileprivate func deviceSupportsTouchId(success: @escaping () -> (), failure: @escaping (NSError) -> ()) {
        let context = LAContext()
        var authError: NSError?
        let touchIdSetOnDevice = context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &authError)
    
        if touchIdSetOnDevice {
            DispatchQueue.main.async {
                 success()
            }
        }
        else {
            DispatchQueue.main.async {
                 failure(error!)
            }
        }
    }
    

    deviceSupportsTouchId() return Success if the device has touch Id capability.

    If not then, function will return error, giving you the following error code if touchIDNotEnrolled is not set yet.

    LAError.Code.touchIDNotEnrolled.rawValue

    You can handle it using this value.

提交回复
热议问题