美文网首页
iOS 11集成Faceid

iOS 11集成Faceid

作者: lesmiserables0 | 来源:发表于2017-11-17 17:42 被阅读271次

class LAContext
struct LAError

let myContext = LAContext()
let myLocalizedReasonString = <#String explaining why app needs authentication#>
 
var authError: NSError?
if #available(iOS 8.0, macOS 10.12.1, *) {
    if myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
        myContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { success, evaluateError in
            if success {
                // User authenticated successfully, take appropriate action
            } else {
                // User did not authenticate successfully, look at error and take appropriate action
            }
        }
    } else {
        // Could not evaluate policy; look at authError and present an appropriate message to user
    }
} else {
    // Fallback on earlier versions
}

相关文章

网友评论

      本文标题:iOS 11集成Faceid

      本文链接:https://www.haomeiwen.com/subject/gggjvxtx.html