iOS 以编程方式取消 TouchID 身份验证对话框

标签 ios touch-id

是否可以在 LAContext.evaluatePolicy 调用后以编程方式取消 TouchID 警报对话框?如果是:如何?

最佳答案

并非 Apple 发布的每个 API 都会在 developer.apple.com(或 Xcode 的文档查看器)上的文档中出现。 API 差异列出了公共(public) API,因此您看到的任何内容都在头文件(请参阅 LocalAuthentication/LAContext.h)和从这些头文件生成的 Swift 接口(interface)中。 header 中的任何内容都是公共(public) API,因此您可以自由调用它。

有时(但不总是)未记录的 API 有很好的标题注释来解释如何使用它们......谢天谢地 LAContext.invalidate() 就是其中之一:

/// Invalidates the context.
///
/// @discussion The context is invalidated automatically when it is (auto)released. This method
///             allows invalidating it manually while it is still in scope.
///
///             Invalidation terminates any existing policy evaluation and the respective call will
///             fail with LAErrorAppCancel. After the context has been invalidated, it can not be
///             used for policy evaluation and an attempt to do so will fail with LAErrorInvalidContext.
///
///             Invalidating a context that has been already invalidated has no effect.
@available(iOS 9.0, *)
public func invalidate()

确实,当 Touch ID 警报可见时调用 invalidate() 似乎应该将其关闭。 (我自己没试过。)


iOS 11 更新:请注意,在配备 Face ID 而不是 Touch ID 的设备上,当您调用 LAContext.evaluatePolicy 时出现的警报/类似 HUD 的 UI 不会t 要求或允许交互,并在成功验证后自动关闭。从理论上讲,invalidate 调用仍然会关闭它(或者如果 Face ID 无法识别用户,则会出现后续的实际交互警报)。

但是假设在所有可能的设备和身份验证方法上您总是有足够的时间在请求后取消 LAContext 身份验证可能并不明智。

关于iOS 以编程方式取消 TouchID 身份验证对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34276412/

相关文章:

ios - Firebase iOS -.queryOrdered().queryEqual(toValue : and child(). observeSingleEvent 之间有什么区别

iphone - 以编程方式安装 .mobileconfig

ios - 应用程序因生物识别而关闭时崩溃

ios - 基本 Touch ID 实现

ios - 使用 touchId 的带有 UIWebview 的 native 应用程序

ios - 如何快速将信息传递给第二个 View Controller 中的 Uilabel?

iphone - 在 itune 配置门户中团队帐户下的不同组之间共享用于分发证书的私钥的任何问题

ios - 未能找到类型 MvxViewModelLoader MvvmCross IOS 的构造函数

objective-c - Touch ID for KeyChain 无 PIN 回退

ios - 从后台 Swift 加载应用程序时如何处理 touchID