IOS8 TouchID Use Introduction

Source: Internet
Author: User

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
    1. -(BOOL) Canevaluatepolicy: (lapolicy) Policy Error: (nserror * __autoreleasing *) error;

2. Call TouchID Recognition interface

[OBJC]View Plaincopy
    1. -(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" >
    1. {
    2. /// Device owner was authenticated using a biometric method.  Biometrics (Touch ID) is required.
    3. // If Touch ID is not enabled, policy evaluation fails.
    4. Lapolicydeviceownerauthenticationwithbiometrics = Klapolicydeviceownerauthenticationwithbiometrics
    5. } 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
  1. Lacontext *context = [[Lacontext alloc] init];
  2. Nserror *contexterror = nil;
  3. NSString *localizedreasonstring = @ "Need authorize";
  4. if ([Context canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:&contexterror]) {
  5. [Context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics
  6. localizedreason:localizedreasonstring
  7. reply:^ (BOOL success, Nserror *error) {
  8. nsstring *title, *message;
  9. if (success) {
  10. title = @ "Authorize Success";
  11. message = Nil;
  12. } Else {
  13. title = @ "Authorize faied";
  14. Message = Error. Localizedfailurereason;
  15. }
  16. Uialertview *alertview = [[Uialertview alloc] initwithtitle:title
  17.                                                                                  &NBSP;MESSAGE:MESSAGE&NBSP;&NBSP;
  18.                                                                                  delegate:nil   
  19.                                                                         Cancelbuttontitle:@ "OK"   
  20. otherbuttontitles: nil];
  21. [Alertview show];
  22. }];
  23. } Else {
  24. Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "Context Error"
  25. message:contexterror. Localizedfailurereason
  26. delegate: nil
  27. cancelbuttontitle:@ "OK"
  28. otherbuttontitles: nil];
  29. [Alertview show];

IOS8 TouchID Use Introduction

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.