Struct LAContext

Source
pub struct LAContext { /* private fields */ }
Expand description

Binding to LAContext of LocalAuthentication

A mechanism for evaluating authentication policies and access controls.

§Overview

You use an authentication context to evaluate the user’s identity, either with biometrics like Touch ID or Face ID, or by supplying the device passcode. The context handles user interaction, and also interfaces to the Secure Enclave, the underlying hardware element that manages biometric data. You create and configure the context, and ask it to carry out the authentication. You then receive an asynchronous callback, which provides an indication of authentication success or failure, and an error instance that explains the reason for a failure, if any.

§Important

Include the NSFaceIDUsageDescription key in your app’s Info.plist file if your app allows biometric authentication. Otherwise, authorization requests may fail.

Implementations§

Source§

impl LAContext

Source

pub fn new() -> Self

create a new LAContext

Source

pub fn set_localized_cancel_title(&mut self, title: &str)

set localizedCancelTitle property.

The localized title for the cancel button in the dialog presented to the user during authentication.

§Discussion

The system presents a cancel button during biometric authentication to let the user abort the authentication attempt. The button appears every time the system asks the user to present a finger registered with Touch ID. For Face ID, the button only appears if authentication fails and the user is prompted to try again. Either way, the user can stop trying to authenticate by tapping the button.

Use the localizedCancelTitle property to choose a title for the cancel button. If you set the property to nil—as it is by default—or assign an empty string, the system uses an appropriate default title, like “Cancel”. Otherwise, provide a localized string that’s short and clear.

Source

pub fn can_evaluate_policy(&self, policy: LAPolicy) -> bool

Assesses whether authentication can proceed for a given policy.

Source

pub async fn evaluate_policy( &self, policy: LAPolicy, localized_reason: &str, ) -> Result<(), LAError>

Evaluates the specified policy.

Trait Implementations§

Source§

impl Default for LAContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for LAContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.