【问题标题】:Xcode passcode - swiftXcode 密码 - 快速
【发布时间】:2018-04-16 11:26:28
【问题描述】:

如何获得系统访问代码? 我想阻止应用程序中的控制器。 我不希望用户创建新代码,但我想使用系统代码。

我看到其他应用程序有这样的功能

Example

【问题讨论】:

标签: swift xcode authentication passcode


【解决方案1】:

无法获取用户密码,但您可以对用户进行身份验证并让他们使用其 TouchID/FaceID

为此,您需要使用LocalAuthentication 框架。

这是一个例子:

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
}

信用:Apple

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 2020-06-17
    • 2016-10-07
    • 2014-06-18
    相关资源
    最近更新 更多