iOS以编程方式取消TouchID身份验证对话框 [英] iOS cancel TouchID authentication dialog programmatically

查看:394
本文介绍了iOS以编程方式取消TouchID身份验证对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 LAContext.evaluatePolicy 调用后以编程方式取消TouchID警告对话框?如果是的话:怎么做?

Is it possible to cancel the TouchID alert dialog programmatically after the LAContext.evaluatePolicy call? If yes: how?

推荐答案

并非Apple发布的所有API都会将其放入developer.apple.com(或Xcode的文档)中docs viewer)。 API差异列出公共API,因此您在头文件中看到的任何内容(请参阅 LocalAuthentication / LAContext.h )以及从这些标头生成的Swift接口。标题中的任何内容都是公共API,因此您可以自由调用它。

Not every API Apple publishes makes it into the documentation on developer.apple.com (or in Xcode's docs viewer). The API diffs list public APIs, so anything you see there is in the header files (see LocalAuthentication/LAContext.h) and the Swift interfaces generated from those headers. And anything that's in the headers is a public API, so you're free to call it.

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

Sometimes (but not always) the undocumented APIs have decent header comments explaining how to use them... thankfully LAContext.invalidate() is one of these:

/// 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()

实际上,看起来调用 invalidate(),而Touch ID警报可见则应将其解除。 (我没有试过自己。)

Indeed, it looks like calling invalidate() while the Touch ID alert is visible should dismiss it. (I haven't tried myself.)

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

iOS 11 update: Note that on devices with Face ID instead of Touch ID, the alert/HUD-like UI that appears when you call LAContext.evaluatePolicy doesn’t require or allow interaction, and dismisses itself upon successful authentication. Theoretically, the invalidate call still dismisses it (or the followup, actually-interactive alert that appears if Face ID doesn’t identify the user).

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

But it might not be wise to assume that on all possible devices and authentication methods you’ll always have enough time to cancel LAContext authentication after asking for it.

这篇关于iOS以编程方式取消TouchID身份验证对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆