【问题标题】:LAContext evaluatePolicy not showing TouchID promptLAContext evaluatePolicy 不显示 TouchID 提示
【发布时间】:2022-11-10 02:06:35
【问题描述】:
func authenticateBiometry(completion: @escaping ErrorHandler) {
    context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: " ") { success, error in
            guard let error = error else {
                if success {
                    completion(nil)
                }
                return
            }
            completion(error)
    }
}

但它仅在第一次提示 touchId/faceId。例如,当我每次点击按钮时,我能做些什么来要求它?假设每 15 秒一次。

【问题讨论】:

  • 就在我的脑海中-如果在按钮点击上调用了上面的方法,您是否尝试在方法开始时重置上下文? let context = LAContext()
  • @stackich,是的,它有效......但是还有其他方法吗?这个很丑,在我看来它不应该像这样工作。

标签: ios swift xcode lacontext


【解决方案1】:

刚刚在本地测试,它对我有用,这是我找到的唯一方法。我在上面看到了您的评论,但我会在这里给出答案,因为可能有人不会觉得它难看哈哈:)。

我花了一些时间在 LAContext 类中搜索某种重置方法,但没有找到任何东西。

解决方案是在按钮点击时调用的方法的开头重置 LAContext:

func authenticateBiometry(completion: @escaping ErrorHandler) {
    context = LAContext() //THIS, implying that context is declared as `var`
    context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: " ") { success, error in
            guard let error = error else {
                if success {
                    completion(nil)
                }
                return
            }
            completion(error)
    }
}

您将能够在每次按钮单击时提示面部/触摸 ID,一旦结束。

【讨论】:

  • 这种方法根本无法测试,但是是的,它当然有效。
  • 对于测试,您可能只需要注入一个工厂对象。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-05
  • 2011-04-06
  • 2020-03-22
  • 2019-07-14
相关资源
最近更新 更多