Easy-to-develop tutorial for IOS---Touch ID password

Source: Internet
Author: User

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

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.