IOS Touch ID Easy to develop tutorial

Source: Internet
Author: User

transferred from: Nsstringfromnamesupport systems and models

The minimum supported system for the IOS system's fingerprint identification is, iPhone 5s iOS 8 although the 5s model of the installation iOS 7 system can use the system-provided fingerprint unlocking function, but because it is API not open, theoretically third-party software is not available.

Dependency Framework
localauthentication.framework #import <LocalAuthentication/LocalAuthentication.h>
Precautions

iOS 8when you do the following versions, be sure to validate the API to avoid invoking the associated API to cause a crash.

using Classes

LAContextFingerprint validation Action Object

Code
1- (void) Authenticateuser2 {3     //Initializing the context object4lacontext* context =[[Lacontext alloc] init];5     //Error Object6nserror* error =Nil;7nsstring* result =@"authentication is needed to access your notes.";8     9     //First Use Canevaluatepolicy to determine the device support statusTen     if([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics error:&ERROR]) { One         //Support Fingerprint Verification A[Context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Localizedreason:result reply:^ (BOOL Success, Nserror *error) { -             if(Success) { -                 //validation successful, main thread processing UI the             } -             Else -             { -NSLog (@"%@", error.localizeddescription); +                 Switch(error.code) { -                      CaseLaerrorsystemcancel: +                     { ANSLog (@"authentication was cancelled by the system"); at                         //Switch to another app, the system cancels the verification touch ID -                          Break; -                     } -                      CaseLaerrorusercancel: -                     { -NSLog (@"authentication was cancelled by the user"); in                         //user cancels authentication touch ID -                          Break; to                     } +                      CaseLaerroruserfallback: -                     { theNSLog (@"User selected to enter custom password"); *[[Nsoperationqueue Mainqueue] addoperationwithblock:^{ $                             //the user chooses to enter the password, switches the main thread processingPanax Notoginseng                         }]; -                          Break; the                     } +                     default: A                     { the[[Nsoperationqueue Mainqueue] addoperationwithblock:^{ +                            //other cases, switch main thread processing -                         }]; $                          Break; $                     } -                 } -             } the         }]; -     }Wuyi     Else the     { -         //fingerprint identification not supported, log out error details Wu          -         Switch(error.code) { About              Caselaerrortouchidnotenrolled: $             { -NSLog (@"TouchID is not enrolled"); -                  Break; -             } A              CaseLaerrorpasscodenotset: +             { theNSLog (@"A passcode have not been set"); -                  Break; $             } the             default: the             { theNSLog (@"TouchID Not available"); the                  Break; -             } in         } the          theNSLog (@"%@", error.localizeddescription); About     } the}
1 typedef ns_enum (Nsinteger, Laerror)2 {3     //Authorization Failure4laerrorauthenticationfailed =klaerrorauthenticationfailed,5     6     //user cancels Touch ID authorization7Laerrorusercancel =Klaerrorusercancel,8     9     //user chooses to enter passwordTenLaerroruserfallback =Klaerroruserfallback, One      A     //System de-authorization (e.g. other app cut-in) -Laerrorsystemcancel =Klaerrorsystemcancel, -      the     //The system does not have a password set -Laerrorpasscodenotset =Klaerrorpasscodenotset, -  -     //device Touch ID is not available, such as not open +Laerrortouchidnotavailable =klaerrortouchidnotavailable, -      +     //device Touch ID not available, user not input Alaerrortouchidnotenrolled =klaerrortouchidnotenrolled, at} ns_enum_available (10_10, 8_0);
Operation Flow

First judge the system version, iOS 8 and the above version of the implementation -(void)authenticateUser method, the method automatically determine whether the device support and open Touch ID .

IOS 9
1  ///authentication is not successful, because there were too many failed Touch ID attempts and2     ///Touch ID is now locked. Passcode is required to unlock Touch ID, e.g. evaluating3     ///Lapolicydeviceownerauthenticationwithbiometrics would ask for passcode as a prerequisite.4Laerrortouchidlockout ns_enum_available (10_11, 9_0) =Klaerrortouchidlockout,5 6     ///authentication was canceled by application (e.g. invalidate is called while7     ///authentication is in progress).8Laerrorappcancel ns_enum_available (10_11, 9_0) =Klaerrorappcancel,9 Ten     ///Lacontext passed to the "has been previously invalidated. OneLaerrorinvalidcontext ns_enum_available (10_11, 9_0) = Klaerrorinvalidcontext

Which, LAErrorTouchIDLockout in 8.0, is also the case, but is not classified as a separate error type, this error occurs, originating from the user repeatedly using Touch ID failure, Touch ID is locked, the user needs to enter a password to unlock, the wrong interaction LocalAuthentication.framework has been encapsulated, do not need the developer care.

LAErrorAppCanceland LAErrorSystemCancel similar, the current software is suspended to cancel the authorization, but the former is the user can not control the hang, such as suddenly come to the phone, the phone app into the foreground, the app is suspended. The latter is the user himself cut to another application, such as pressing the home key to hang.

LAErrorInvalidContextWell understood, that is the authorization process, the Lacontext object is released, resulting in authorization failure

IOS Touch ID Easy to develop tutorial

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.