LAContext: canEvaluatePolicy() method
The canEvaluatePolicy() method answers whether authentication with a given policy is possible right now. It returns synchronously and shows no UI.
Syntax
canEvaluatePolicy(policy)Parameters
policy
The policy, 'deviceOwnerAuthenticationWithBiometrics' or 'deviceOwnerAuthentication'; see Policies.
Return value
A boolean.
true: the system can start authentication whenevaluatePolicy()is called.false: it cannot start, for one of the reasons in the "When authentication is not possible" column of the Policies table. To find out which, askcanEvaluatePolicyError().- An object that has had
invalidate()called returnsfalse.
The result can change: the user can enroll or delete a face in the system Settings at any time. Ask when you are about to use it.
Exceptions
TypeError
The policy is unrecognized, missing, or not a string:
canEvaluatePolicy has no value "biometrics"; expected one of: deviceOwnerAuthenticationWithBiometrics / deviceOwnerAuthenticationExamples
js
const context = new LAContext();
console.log(context.canEvaluatePolicy('deviceOwnerAuthenticationWithBiometrics'));
console.log(context.canEvaluatePolicy('deviceOwnerAuthentication'));Result: Prints two booleans. On a simulator with no face enrolled and no passcode set, the first line is false.
Corresponding iOS API
The return value of -[LAContext canEvaluatePolicy:error:]. The error out-parameter is returned by canEvaluatePolicyError().