Use Touch ID fingerprint to unlock and use Touch ID fingerprint to unlock

Source: Internet
Author: User

Use Touch ID fingerprint to unlock and use Touch ID fingerprint to unlock

Touch ID is a new feature added after iPhone 5 s, which is a well-known fingerprint recognition technology. In most cases, you may need to perform screen decoding on your mobile phone. You do not need to enter the four-digit password of your mobile phone for verification as before. On the one hand, you don't have to worry about the password being seen by others, and on the other hand, it facilitates your operations. After iOS 8, Apple opened the Touch id api for developers, which also brought a new experience to our apps.

Use

The Touch id api is very easy to understand. before using it, we need to import the LocalAuthentication library. Key modules are introduced: LAcontext

Apple is not fully open to Touch ID, but has opened the following two interfaces:

(1) canEvaluatePolicy: error: identify whether Touch ID can be authenticated

(2) evaluatePolicy: localizedReson: reply: authentication Touch ID

The key code is as follows:

LAContext * myContext = [[LAContext alloc] init];

NSError * authError = nil;

NSString * mylodomainzedreasonstring = @ "scan your fingerprint .";

If ([myContext canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics error: & authError]) {

[MyContext evaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason: myLocatizedReasonString reply: ^ (BOOL success, NSError * _ Nullable error ){

If (success ){

Dispatch_async (dispatch_get_main_queue (), ^ {

// Update the UI in the main thread. Otherwise, the UI will become stuck.

TouchViewController * touchVC = [[TouchViewController alloc] init];

[Self. navigationController pushViewController: touchVC animated: YES];

});

}

If (! Success ){

NSLog (@ "% @", error );

}

}];

}

Error Handling

Typedef NS_ENUM (NSInteger, LAError)

{

// User verification fails. For example, an incorrect finger fingerprint is provided.

LAErrorAuthenticationFailed = kLAErrorAuthenticationFailed,

// The user has canceled Touch ID verification.

LAErrorUserCancel = kLAErrorUserCancel,

// You do not want to perform Touch ID verification or enter a password.

LAErrorUserFallback = kLAErrorUserFallback,

// Verification terminated

LAErrorSystemCancel = kLAErrorSystemCancel,

// The user has not set the password in the device Settings

LAErrorPasscodeNotSet = kLAErrorPasscodeNotSet,

// The device does not support Touch ID

LAErrorTouchIDNotAvailable = kLAErrorTouchIDNotAvailable,

// No Touch ID fingerprint is registered on the device

LAErrorTouchIDNotEnrolled = kLAErrorTouchIDNotEnrolled,

} NS_ENUM_AVAILABLE (10_10, 8_0 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.