Fingerprint Unlock for iOS development

Source: Internet
Author: User

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

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.