In IOS8, developers can use APIs that open Touch ID permissions to third-party apps so that they use fingerprint authentication in their apps to complete the user authentication section.
This article mainly describes how to integrate in the application Touch ID to verify the identity of the user.
#import <LocalAuthentication/LocalAuthentication.h>This library must be Xcode6 and connected to a real machine to not prompt for errors that cannot be found. If this is the emulator, you will be prompted not to find the library.
1-(Ibaction) authenticatebuttontapped: (ID) Sender {2Lacontext *context =[[Lacontext alloc] init];3Context.localizedfallbacktitle =@"Enter Password";4Nserror *error =Nil;5 6 if([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics error:&ERROR]) {7 8 [Context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics9Localizedreason:@"Are you the owner of this device? "Tenreply:^ (BOOL success, Nserror *error) { One if(Success) { ADispatch_async (Dispatch_get_main_queue (), ^{ - -Uialertview *alert = [[Uialertview alloc] Initwithtitle:@"Success" theMessage@"you are the owner of the device. " - Delegate: Nil -Cancelbuttontitle:@"Ok" - Otherbuttontitles:nil]; + [alert show]; - }); + A}Else{ at - - /* - //The user does not provide a valid certificate (3 Chance Failure-authentication failed). - laerrorauthenticationfailed = klaerrorauthenticationfailed, - in //The authentication is canceled (the user clicks the Cancel button). - laerrorusercancel = Klaerrorusercancel, to + //The authentication is canceled, the user clicks the fallback button (enter the password). - laerroruserfallback = Klaerroruserfallback, the * //Authentication is canceled by the system (e.g. another application goes to the foreground). $ laerrorsystemcancel = Klaerrorsystemcancel,Panax Notoginseng - //authentication cannot start because the password is not set on the device. the Laerrorpasscodenotset = Klaerrorpasscodenotset, + A //Authentication failed to start because the Touch ID is not available on the device. the laerrortouchidnotavailable = klaerrortouchidnotavailable, + - //Authentication failed to start because there is no registered finger Touch ID. When the fingerprint password is not set. $ laerrortouchidnotenrolled = klaerrortouchidnotenrolled, $ **/ - Switch(error.code) { - Caselaerrorauthenticationfailed: theNSLog (@"authentication failed. "); - Wuyi Break; the - CaseLaerrorusercancel: WuNSLog (@"The user clicks the Cancel button. "); - About Break; $ - CaseLaerroruserfallback: -NSLog (@"user clicks Enter password. "); - A Break; + the CaseLaerrorsystemcancel: -NSLog (@"another application to the front desk"); $ the Break; the the CaseLaerrorpasscodenotset: theNSLog (@"The password is not set on the device"); - in Break; the the Caselaerrortouchidnotavailable: AboutNSLog (@"Touch ID is not available on the device"); the the Break; the + Caselaerrortouchidnotenrolled: -NSLog (@"the finger Touch ID is not registered. "); the Bayi Break; the the default: -NSLog (@"Touch ID Not configured"); - the Break; the } the } the }]; - the}Else { theDispatch_async (Dispatch_get_main_queue (), ^{ the 94Uialertview *alert = [[Uialertview alloc] Initwithtitle:@"Error Hints" theMessage@"your device does not have a Touch ID." the Delegate: Nil theCancelbuttontitle:@"Ok"98 Otherbuttontitles:nil]; About [alert show]; - });101 }102 103}
which
(1) Localizedfallbacktitle: Used to set the name of the button on the left, default is输入密码。
(2) Localizedreason: Used to set a prompt to indicate why you want to use touch ID, such as @ "Are you the owner of this device?" ".
The official API is simple, just a few words can be.
Using TouchID checksum in iOS8