Instance Method

evaluatePolicy(_:localizedReason:reply:)

Evaluates the specified policy.

Declaration

func evaluatePolicy(_ policy: LAPolicy, localizedReason: String, reply: @escaping (Bool, Error?) -> Void)

Parameters

policy

The policy to evaluate. For possible values, see LAPolicy.

localizedReason

The app-provided reason for requesting authentication, which displays in the authentication dialog presented to the user. In macOS this appears in the title, and in iOS this appears in the subtitle. This string should be provided in the user’s current language and should be short and clear. It should not contain the app name, because that appears elsewhere in the authentication dialog.

reply

A block that is executed when policy evaluation finishes. This block is evaluated on a private queue internal to the framework in an unspecified threading context. You must not call canEvaluatePolicy(_:error:) in this block, because doing so could lead to deadlock.

success

true if policy evaluation succeeded, otherwise false.

error

nil if policy evaluation succeeded, an error object that should be presented to the user otherwise. See LAError.Code for possible error codes

Discussion

This method asynchronously evaluates an authentication policy. The reply block is used to deliver the results of the evaluation. Evaluating a policy may involve prompting the user for various kinds of interaction or authentication. The actual behavior is dependent on the evaluated policy and device type. It can also be affected by installed configuration profiles.

You should not assume that a previous successful evaluation of a policy necessarily leads to a subsequent successful evaluation. Policy evaluation can fail for various reasons, including cancelation by the user or the system.