ios - 如果我在 iOS 8 上使用 LAPolicyDeviceOwnerAuthentication 会怎样?

标签 ios objective-c touch-id

在我的应用程序中,我想知道用户是否设置了密码或指纹 (touchID)。为此有一个非常简单的方法:[LAContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:error]

然而,Apple's docsLAPolicyDeviceOwnerAuthentication 仅适用于 iOS9 及更高版本。我宁愿不解释就让 iOS 8 用户崩溃,即使它变老了。问题是,我已经在 iOS8.4 模拟器上试过了,它似乎可以编译并正常工作。

如果我在 iOS 8 上使用 LAPolicyDeviceOwnerAuthentication 会产生什么不良影响?

最佳答案

我使用类似这样的代码:

LAPolicy localAuthPolicy = LAPolicyDeviceOwnerAuthenticationWithBiometrics;
if (![[UIDevice currentDevice].systemVersion hasPrefix:@"8."]) {
    localAuthPolicy = LAPolicyDeviceOwnerAuthentication;
}

这确保我只在 iOS 9 及更高版本上使用 LAPolicyDeviceOwnerAuthentication

当您尝试使用 LAPolicyDeviceOwnerAuthentication 时,在 iOS 8 设备上实际发生的情况没有记录。任何事情都不太可能崩溃,但身份验证可能会由于未知值而返回 NO,或者它可能会成功,因为 iOS 8 只有一个有效值并且它可能不会进行任何检查。

不幸的是,Objective-C 不提供对有效枚举值的任何运行时检查,就像您可以对常量、方法和类所做的那样。

关于ios - 如果我在 iOS 8 上使用 LAPolicyDeviceOwnerAuthentication 会怎样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39475550/

相关文章:

ios - 从 String 中去除前导、尾随和超过 1 个空格

objective-c - 使用蒙版比较图像

objective-c - 混合两个图像并从两个 UIImageViews 绘制调整大小的图像

iphone - 在 FTP 上上传多个文件

ios - TouchID 取消应该关闭 View Controller

ios - 更改图像时 UIButton 变得不可见

iPhone/Objective-C : using singleton class as a container for globals

objective-c - 尝试将 NSString 解析为 NSDate 时出错

ios - 从后台返回时使用 FaceID 或 TouchID 对登录用户进行身份验证

ios - becomeFirstResponder 有时无法打开 ios 10 上的键盘