This article reprinted to http://blog.csdn.net/jinkaiouyang/article/details/35555123
IOS8 is opening up the fingerprint recognition technology. We are able to use user-set Touch ID for user authentication.
The TouchID API is primarily integrated into the localauthentication.framework. Add the framework to the project and require the support of iphone5s and IOS8 systems to use the TouchID API
The
The TouchID API is simple:
1, before use, you need to determine whether TouchID support
[OBJC]View Plaincopy
- -(BOOL) Canevaluatepolicy: (lapolicy) Policy Error: (nserror * __autoreleasing *) error;
2. Call TouchID Recognition interface
[OBJC]View Plaincopy
- -(void) EvaluatePolicy: (lapolicy) Policy Localizedreason: (nsstring *) Localizedreason reply: ( void (^) (BOOL success, nserror *error)) reply;
Policy enumeration, which represents the permission to be used, currently has only one biometrics, meaning TouchID
[OBJC]View Plaincopy < param name= "wmode" value= "Transparent" >
- {
- /// Device owner was authenticated using a biometric method. Biometrics (Touch ID) is required.
- // If Touch ID is not enabled, policy evaluation fails.
- Lapolicydeviceownerauthenticationwithbiometrics = Klapolicydeviceownerauthenticationwithbiometrics
- } ns_enum_available (10_10, 8_0);
Localizedreason
Use TouchID for reasons that will appear in the pop-up box, prompting the user. This field must be filled in and not nil or empty, otherwise it will throw a nsinvalidargumentexception exception.
(void (^) (BOOL success,nserror *error))
TouchID The result of the input callback. Use block mode.
Example code:
[OBJC]View Plaincopy
- Lacontext *context = [[Lacontext alloc] init];
- Nserror *contexterror = nil;
- NSString *localizedreasonstring = @ "Need authorize";
- if ([Context canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:&contexterror]) {
- [Context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics
- localizedreason:localizedreasonstring
- reply:^ (BOOL success, Nserror *error) {
- nsstring *title, *message;
- if (success) {
- title = @ "Authorize Success";
- message = Nil;
- } Else {
- title = @ "Authorize faied";
- Message = Error. Localizedfailurereason;
- }
- Uialertview *alertview = [[Uialertview alloc] initwithtitle:title
- &NBSP;MESSAGE:MESSAGE&NBSP;&NBSP;
- delegate:nil
- Cancelbuttontitle:@ "OK"
- otherbuttontitles: nil];
- [Alertview show];
- }];
- } Else {
- Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "Context Error"
- message:contexterror. Localizedfailurereason
- delegate: nil
- cancelbuttontitle:@ "OK"
- otherbuttontitles: nil];
- [Alertview show];
IOS8 TouchID Use Introduction