Support Systems and Models:The minimum supported system for the iOS system's fingerprint identification is,
iPhone 5s although the 5s model of the
iOS 8 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. Dependent framework:
Localauthentication.framework#import <LocalAuthentication/LocalAuthentication.h>
Precautions:
iOS 8 When you do the following versions, be sure to validate the API to avoid invoking the associated API to cause a crash. Use class:
LAContext Fingerprint Validation Action objectCode:
-(void) authenticateuser{//Initialize context object lacontext* contextual = [[Lacontext alloc] init]; Wrong object nserror* error = Nil; nsstring* result = @ "Authentication is needed to access your notes."; First use Canevaluatepolicy to determine if the device supports the status if ([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:&error]) {//Support fingerprint verification [context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Locali Zedreason:result reply:^ (BOOL success, Nserror *error) {if (success) {//validation succeeded, main thread processing UI } else {NSLog (@ "%@", error.localizeddescription); Switch (error.code) {case laerrorsystemcancel: {NSLog (@ "Aut Hentication is cancelled by the system "); Switch to another app, the system cancels the verification touch ID break; } Case Laerrorusercancel: { NSLog (@ "Authentication is cancelled by the user"); User cancels authentication touch ID break; } case Laerroruserfallback: {NSLog @ ' User selected to enter Custom password "); [[Nsoperationqueue Mainqueue] addoperationwithblock:^{//user Select Enter password, switch main thread processing }]; Break } default: {[[Nsoperationqueue Mainqueue] Addoperationwithbl ock:^{//Other case, switch main thread processing}]; Break } } } }]; } else {//does not support fingerprint identification, log out error details switch (error.code) {case laerrortouchidnotenrolled: {NSLog (@ "TouchID is not enrolled"); Break} case Laerrorpasscodenotset: {NSLog (@ "A passcode have not been set"); Break } default: {NSLog (@ "TouchID not available"); Break }} NSLog (@ "%@", error.localizeddescription); [Self showpasswordalert]; }}
typedef ns_enum (Nsinteger, laerror) { //authorization failed laerrorauthenticationfailed = klaerrorauthenticationfailed, //user cancels Touch ID authorization Laerrorusercancel = klaerrorusercancel, //user chooses to enter password laerroruserfallback = Klaerroruserfallback, //System de-authorization (such as other app cut-in) Laerrorsystemcancel = klaerrorsystemcancel, //System not set password laerrorpasscodenotset = Klaerrorpasscodenotset, //device Touch ID not available, for example not open laerrortouchidnotavailable = Klaerrortouchidnotavailable, //device Touch ID not available, user not input laerrortouchidnotenrolled = Klaerrortouchidnotenrolled,} 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 .
Easy development tutorial for IOS---Touch ID password