ios - Swift ios touch id 登录流程

标签 ios iphone swift touch-id

在我的应用程序中,用户可以使用电子邮件/密码验证/登录到我的后端。现在我也在考虑实现触摸 ID。

但我对使用触摸 ID 的登录流程感到困惑。

使用下面的代码我可以轻松验证用户:

func authenticateUser() {
    let context = LAContext()
    var error: NSError?

    if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
        let reason = "Identify yourself!"

        context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
            [unowned self] success, authenticationError in

            DispatchQueue.main.async {
                if success {
                    self.runSecretCode()
                } else {
                    let ac = UIAlertController(title: "Authentication failed", message: "Sorry!", preferredStyle: .alert)
                    ac.addAction(UIAlertAction(title: "OK", style: .default))
                    self.present(ac, animated: true)
                }
            }
        }
    } else {
        let ac = UIAlertController(title: "Touch ID not available", message: "Your device is not configured for Touch ID.", preferredStyle: .alert)
        ac.addAction(UIAlertAction(title: "OK", style: .default))
        present(ac, animated: true)
    }
}

但我不知道是哪个用户。

因此,当用户创建帐户时,我是否应该在我的数据库中存储设备 ID(如果存在)之类的东西,然后当用户使用触摸 ID 时,我可以检查它是什么设备 ID,然后让用户登录?

最佳答案

据我了解,touch ID 仅充当 native 应用本身的看门人,而不是 API。

无论如何,您的用户都必须至少通过 API 进行一次身份验证才能获得某种 secret token (JWT 等),然后通过关闭/打开应用程序来保留这些 token 。在您的应用程序开始调用 API 之前,Touch ID 必须成功,但 API 将仅根据密码进行验证。

通过这种方式,您可以在不保存凭据的情况下保留用户的登录名,并且您在应用程序上拥有触摸 ID,以防止不需要的用户拿起未锁定的手机并打开银行应用程序。

我的理解是这样的,如果有错,请大家指正。

关于ios - Swift ios touch id 登录流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41048805/

相关文章:

ios - 使用 .xcworkspace React Native run-ios

iphone - iTunes 连接中的无效二进制错误

ios - 当我试图让用户创建他们自己的 uicollectionviewcell 时,iOS 模拟器中没有出现任何内容

python - 将 OpenCV-Python 转换为 C++/Objective C

ios - 在 UIViewController 中使用自定义 UITableView

ios - 在 Swift 4 中使用 UISwitch 启用和禁用位置

ios - 向苹果商店提交应用程序(验证问题)

iphone - 为什么 NSFetchedResultsController 在设置获取批量大小时加载所有行?

ios - 安装 SpinWheelControl Cocoapod 出现 "the compiler is unable to type check this expression in time"错误

ios - Swift,tableview 没有被填充