IOS 8 user authentication with Touch ID

Source: Internet
Author: User

The SDK for IOS 8 opens the interface for Touch ID. You can see from the WWDC video that Touch ID is applied in two ways: for key chain encryption and for authorization. iOS 8 release we can see Evernote iOS The app is already integrated with this feature. Here's how to implement identity authentication using Touch ID.In fact, all of the interfaces used for identity authentication are in the Localauthentication framework, which actually has only three header files:LAContext.hLAError.hLAPublicDefines.hThe actual function used is only two://To determine if the device supports touch ID  - (BOOL) Canevaluatepolicy: (Lapolicy) Policy error: (Nserror* __autoreleasing*) error;//functions that really verify identities  - (void) EvaluatePolicy: (Lapolicy) PolicyLocalizedreason: (NSString *) Localizedreason
Reply: (void(^)(BOOL Success, Nserror *error)) Reply;
Both of these functions are Lacontext member function. Currently Lapolicy has only one value:lapolicydeviceownerauthenticationwithbiometrics.

if Canevaluatepolicy Returns Yes, indicating that the device supports fingerprint recognition, then you can call EvaluatePolicy: function for fingerprint recognition. After calling the EvaluatePolicy function, an alert pops up, such as:



the alert can be customized in only two places:1. The "To access your photos" Hint text is made bythe Localizedreason parameter is specified to explain to the user the purpose of using Touch ID.2. "Enter Password" can be set by the Localizedfallbacktitle property of Lacontext (Lacontext currently only has this property), if not set, the default is "enter Password ". It is important to note that if this property is set to @" "(An empty string), the button will be hidden and Evernote should do so.the rest, of course, not to mention getting the user's fingerprint data.In theory three cases will exit the validation (alert will be called by the dismiss,reply callback):1. User Fingerprint verification2. The user clicks the "Enter Password" button3. The user clicks the "Cancel" buttonAnother situation: the user entered the wrong fingerprint. In this case, the alert will not be dismiss and its title will be changed from "Touch ID" to "Try Again", with a spring-like animation effect. OK, here's the code (don't forget to introduce the header file <LocalAuthentication/LocalAuthentication.h>):Lacontext*context = [LacontextNew];

Nserror*error;
Context.Localizedfallbacktitle=@"";

if([Context Canevaluatepolicy:LapolicydeviceownerauthenticationwithbiometricsError: &error]) {
NSLog(@ "Touch ID is available.");
[ContextEvaluatePolicy:Lapolicydeviceownerauthenticationwithbiometrics Localizedreason:nslocalizedstring(@ "Use Touch ID to log in.",Nil) reply:^(BOOLSuccess,Nserror*error) {
            if(Success) {
NSLog(@ "authenticated using Touch ID.");
} Else{                if(error. )Code== Klaerroruserfallback) {                    NSLog(@ "User tapped Enter Password");
} Else if (error. )Code == Klaerrorusercancel) {
 NSLog(@ "User tapped Cancel");
} Else {
 NSLog(@ "authenticated failed.");}
}];
}Else{
NSLog(@ "Touch ID is not available:%@", error);
}

IOS 8 user authentication with Touch ID

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.