Chaosed0 Chaosed0 - 8 months ago 59
Objective-C Question

What happens if I use LAPolicyDeviceOwnerAuthentication on iOS 8?

In my app, I would like to know if the user has setup a passcode or fingerprint (touchID). There's a pretty easy method just for that:

[LAContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:error]

However, Apple's docs say
is only available on iOS9 and above. I would rather not crash iOS 8 users without explanation, even if it is getting older. The thing is, I've tried it on an iOS8.4 simulator, and it seems to compile and just work.

What ill effects can happen if I use
on iOS 8?


I use code similar to this:

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

This ensures I only use LAPolicyDeviceOwnerAuthentication on iOS 9 and later.

It's undocumented what actually happens on an iOS 8 device when you attempt to use LAPolicyDeviceOwnerAuthentication. It's very unlikely anything will crash but the authentication may return NO due to an unknown value or it may succeed because iOS 8 only had one valid value and it may not do any checking.

Unfortunately Objective-C doesn't provide any runtime checks for valid enum values like you can do with constants, methods, and classes.