iOS使用Touch ID自定义本地身份验证

时间:2016-11-28 08:50:45

标签: ios swift authentication swift3 touch-id

我使用以下代码在我的应用程序中实现touchID /密码验证

let context : LAContext = LAContext()
    var error: NSError?

    // Check if the device can evaluate the policy.
    if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthentication, error: &error) {
        context.evaluatePolicy(LAPolicy.deviceOwnerAuthentication,
                                localizedReason: messageString,
                                reply: { (success: Bool, evalPolicyError: Error?) -> Void in

            if success {
                // ...
            }
            else {

                switch evalPolicyError!._code {

                case LAError.systemCancel.rawValue:
                    print("Authentication was cancelled by the system")

                case LAError.userCancel.rawValue:
                    print("Authentication was cancelled by the user")

                case LAError.userFallback.rawValue:
                    print("User selected to enter custom password")
                    OperationQueue.main.addOperation({ () -> Void in
                        // ...
                    })

                default:
                    print("Authentication failed")
                    OperationQueue.main.addOperation({ () -> Void in
                        // ...
                    })
                }
            }

        })
    }

可以自定义吗?例如:

  1. 在切换到密码之前选择TouchID次尝试次数?
  2. 在第一个AlertView中,让用户选择使用按钮切换到密码(在当前实现中,只有在TouchID验证失败时才能访问密码)

0 个答案:

没有答案