Corebluetooth-touchid applications

Source: Internet
Author: User

Support Systems and Models:

The minimum supported models for the IOS system's fingerprint recognition feature are the iPhone 5s minimum supported iOS 8 system,

Although iOS 7系统的5s the installation model can use the system-provided fingerprint unlock function, but because it is API not open, so theoretically third-party software is not available.

Dependency Framework
LocalAuthentication.framework#import <LocalAuthentication/LocalAuthentication.h>
Precautions

When making the iOS 8以下 version adaptation, be sure to do API验证 so to avoid invoking the associated API to cause a crash.

if(iOS8){xxx} // 系统版本验证if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError])
Using classes

LAContextFingerprint validation Action Object

Operation Flow
    • To determine the system version, IOS 8 and later version execution-(void) Authenticateuser method,
    • Method automatically determines whether the device supports and turns on touch ID.
code example
1 #import "ViewController.h"2 #import "mbprogresshud+mj.h"3 #import<LocalAuthentication/LocalAuthentication.h>4 5 #defineIOS8 ([Uidevice currentdevice].systemversion.doublevalue >= 8.0)6 7 8 @interfaceViewcontroller ()9-(Ibaction) Clickmethod: (ID) sender;Ten  One @end A  - @implementationViewcontroller -  the- (void) Viewdidload { - [Super Viewdidload]; -     //additional setup after loading the view, typically from a nib. - } +  -  +-(Ibaction) Clickmethod: (ID) Sender { A      at     if(!IOS8) {//iOS8 later support TouchID -         //HUD Hints -[Mbprogresshud ShowError:@"The current system does not support TouchID"]; -         return; -     } -      in     //Call TouchID - [self touchidshow]; to      + } -  the- (void) Touchidshow * { $     //Create a fingerprint check objectPanax NotoginsengLacontext *context =[[Lacontext alloc] init]; -      theNserror *error1 =Nil; +     if([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics error:&Error1]) { A         //Popup Validation the[Context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Localizedreason:@"TouchID Error"reply:^ (BOOL success, Nserror *_nullable Error) { +             -             if(success) {//Validation Successful $NSLog (@"Success"); $}Else{ -                 Switch(error.code) { -                      CaseLaerrorsystemcancel: the                     { -NSLog (@"authentication was cancelled by the system");Wuyi                         //Switch to another app, the system cancels the verification touch ID the                          Break; -                     } Wu                      CaseLaerrorusercancel: -                     { AboutNSLog (@"authentication was cancelled by the user"); $                         //user cancels authentication touch ID -                          Break; -                     } -                      CaseLaerroruserfallback: A                     { +NSLog (@"User selected to enter custom password"); the[[Nsoperationqueue Mainqueue] addoperationwithblock:^{ -                             //the user chooses to enter the password, switches the main thread processing $                         }]; the                          Break; the                     } the                     default: the                     { -[[Nsoperationqueue Mainqueue] addoperationwithblock:^{ in                             //other cases, switch main thread processing the                         }]; the                          Break; About                     } the                 } theNSLog (@"\n%s\n---line=%d\n--error=%@\n", __function__, __line__, error.localizeddescription); the             } +         }]; -          the}Else{Bayi         Switch(error1.code) { the              Caselaerrortouchidnotenrolled: theNSLog (@"laerrortouchidnotenrolled"); -                  Break; -                  the                  the              CaseLaerrorpasscodenotset: theNSLog (@"Laerrorpasscodenotset");//The Showpasscoderesetalert method is triggered here the                  Break; -                  the             default: theNSLog (@"Touch ID is unaviliable"); the                  Break;94         } the     } the     /* the typedef ns_enum (Nsinteger, Laerror)98      { About //Authorization failed - laerrorauthenticationfailed = klaerrorauthenticationfailed,101      102 //user cancels Touch ID authorization103 laerrorusercancel = Klaerrorusercancel,104       the //user chooses to enter password106 laerroruserfallback = Klaerroruserfallback,107      108 //System de-authorization (such as other app cut-in)109 laerrorsystemcancel = Klaerrorsystemcancel, the      111 //System not set password the Laerrorpasscodenotset = Klaerrorpasscodenotset,113       the //device Touch ID not available, e.g. not open the laerrortouchidnotavailable = klaerrortouchidnotavailable, the      117 //device Touch ID not available, user not input118 laerrortouchidnotenrolled = klaerrortouchidnotenrolled,119 } ns_enum_available (10_10, 8_0); -      121      */122     123 [self dealwitherror:error1];124 } the 126 127- (void) Dealwitherror: (Nserror *) Error - {129     if(Error) { theNSLog (@"error =%@", error.localizeddescription);131     } the }133 @end

Corebluetooth-touchid applications

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.