A while ago has been in the progress of the project, not too much time to write a blog, now finally free, the previous owed to the blog to fill up.
After iOS8.0, the API opens up the functionality of fingerprint verification. Although the open API can only be used as a validation, it is more restrictive, but it is sufficient for apps with similar "gesture password" functionality. With this new API, you can unlock a large number of apps in the app.
The minimum hardware support for the Fingerprint verification feature is Iphone5s,ipad 6,ipad Mini 3 These devices with Touch ID hardware support, and the operating system is at least iOS8.0, because Touch ID is a class of APIs that are open after iOS8.0.
Put the code below.
When you do iOS8.0 the next version, be sure to validate the API to avoid invoking the associated API to cause a crash.
To introduce a dependent framework:
#import <LocalAuthentication/LocalAuthentication.h>
Implementation of fingerprint verification
-(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 other authentication method, 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]; }}
A description of several situations
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);
Fingerprint Unlock for iOS development