gpt4 book ai didi

ios - 如何在 iOS 8 中使用 Touch ID 传感器

转载 作者:IT王子 更新时间:2023-10-29 05:46:48 25 4
gpt4 key购买 nike

iOS 8 最令我兴奋的事情之一是能够在 iPhone 5s 及更新机型上使用指纹传感器。不幸的是,我找不到所需的框架,也不知道如何进行身份验证。请帮助我:

  • 使用 Touch ID 需要什么框架?
  • 如何使用它的方法以及如何对用户进行身份验证?

非常感谢代码示例。

最佳答案

更完整的片段,swift 风格:

func authenticateUser() {
// Get the local authentication context.
let context = LAContext()

// Declare a NSError variable.
var error: NSError?

// Set the reason string that will appear on the authentication alert.
var reasonString = "Authentication is needed to access your notes."

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

if success {

}
else{
// If authentication failed then show a message to the console with a short description.
// In case that the error is a user fallback, then show the password alert view.
println(evalPolicyError?.localizedDescription)

switch evalPolicyError!.code {

case LAError.SystemCancel.toRaw():
println("Authentication was cancelled by the system")

case LAError.UserCancel.toRaw():
println("Authentication was cancelled by the user")

case LAError.UserFallback.toRaw():
println("User selected to enter custom password")
self.showPasswordAlert()

default:
println("Authentication failed")
self.showPasswordAlert()
}
}

})]
}
else{
// If the security policy cannot be evaluated then show a short message depending on the error.
switch error!.code{

case LAError.TouchIDNotEnrolled.toRaw():
println("TouchID is not enrolled")

case LAError.PasscodeNotSet.toRaw():
println("A passcode has not been set")

default:
// The LAError.TouchIDNotAvailable case.
println("TouchID not available")
}

// Optionally the error description can be displayed on the console.
println(error?.localizedDescription)

// Show the custom alert view to allow users to enter the password.
self.showPasswordAlert()
}
}

Source

关于ios - 如何在 iOS 8 中使用 Touch ID 传感器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24158062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com