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

What happens if I use LAPolicyDeviceOwnerAuthentication on iOS 8?

在我的应用程序中,我想知道用户是否设置了密码或指纹 (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 设备上实际发生的情况。任何事情都不太可能崩溃,但身份验证可能 return NO 由于未知值或者它可能成功,因为 iOS 8 只有一个有效值并且它可能不进行任何检查。

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

所做的那样

如果您在 iOS9 以下的任何内容上使用 LAPolicyDeviceOwnerAuthentication,应用程序将会崩溃。当我没有意识到这在 iOS 9 以下的任何东西上都不可用时,我的应用程序就发生了这种情况,但我的应用程序支持 iOS 8.x 作为其最低支持 OS版本。