A brief introduction to fingerprint recognition in iOS development

Source: Internet
Author: User

A simple introduction to fingerprint recognition in the iphone series, which began with the fingerprint recognition function from the 5S onwards, opened the interface for fingerprint verification at the time of iOS8.

So we have to judge the model and the version of the system in the fingerprint identification application.

The code below, the following need to pay special attention is actually the difference between lapolicydeviceownerauthentication and Lapolicydeviceownerauthenticationwithbiometrics, And the version of the detection system through [Uidevice Currentdevice].systemversion.floatvalue, determine if the device is available Touch ID is through Canevaluatepolicy:error: This method to make judgments. It is also important to note that the following verification of the success of the fingerprint is done by default in the sub-thread, so if we want to do the UI operation to go back to the main thread to execute. This function can be implemented using Dispatch_async (dispatch_queue_t _nonnull queue, ^{}), which is passed into the home queue. There is also we can according to Eror code to make some judgments, look at the user specifically for what causes the error, and then make the corresponding output.

  1. 1, determine whether the system version is greater than or equal to 8.0 if greater than equals, it means that fingerprint identification can be used
  2. if ([Uidevice currentdevice].systemversion.floatvalue>=8.0)
  3. {
  4. The ability to determine if fingerprint recognition can be used is only possible after 5S.
  5. Create a context for a La object
  6. Lacontext * context = [[Lacontext alloc]init];
  7. Determine if the device supports fingerprint identification
  8. Evaluate means to evaluate
  9. Policy represents a strategy
  10. Used to check if the current device is available TouchID
  11. if ([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:nil])
  12. {
  13. Lapolicydeviceownerauthentication if we three times the fingerprint input is wrong, it will pop up the password box, if you do not enter the password. There are two chances to verify fingerprints if they're
  14. The error will continue to eject the System password box so you can enter it if you do not enter the Touch ID and the lapolicydeviceownerauthenticationwithbiometrics will not eject the input system.
  15. Password box, enter three errors after the default does not do any processing, we can also re-click on the fingerprint recognition for input, but if you enter the error two times after the Touch ID will be locked
  16. Indicates that fingerprint recognition technology can be used
  17. [Context evaluatepolicy:lapolicydeviceownerauthentication localizedreason:@ "Please verify the fingerprint for payment" reply:^
  18. (BOOL success, Nserror * _nullable error) {
  19. The inside is executed in the sub-thread, so to update the UI, it must be back to the main thread to execute the
  20. Judging whether it is successful
  21. if (success)
  22. {
  23. NSLog (@ "%@", [Nsthread CurrentThread]);
  24. NSLog (@ "verify success");
  25. }
  26. Else
  27. {
  28. NSLog (@ "Verification failed");
  29. }
  30. NSLog (@ "%@", [Nsthread CurrentThread]);
  31. NSLog (@ "%@", error);
  32. if (Error)
  33. {
  34. if (error.code==-2)
  35. {
  36. Dispatch_async (Dispatch_get_main_queue (), ^{
  37. Uialertcontroller * VC = [Uialertcontroller alertcontrollerwithtitle:@ "Fingerprint verification Cancel" message:@ ""
  38. Preferredstyle:uialertcontrollerstylealert];
  39. Uialertaction * action = [uialertaction actionwithtitle:@ "Confirm" style:uialertactionstyledefault
  40. handler:^ (uialertaction * _nonnull action) {
  41. NSLog (@ "---------");
  42. }];
  43. Uialertaction * Action1 = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel
  44. handler:^ (uialertaction * _nonnull action) {
  45. NSLog (@ "hhhhhh");
  46. }];
  47. [VC addaction:action];
  48. [VC Addaction:action1];
  49. [Self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil];
  50. });
  51. }
  52. else if (error.code==-1)
  53. {
  54. Dispatch_async (Dispatch_get_main_queue (), ^{
  55. Uialertcontroller * VC = [Uialertcontroller alertcontrollerwithtitle:@ "fingerprint has been wrong 3 times" message:
  56. @ "You have two more chances" preferredstyle:uialertcontrollerstylealert];
  57. Uialertaction * action = [uialertaction actionwithtitle:@ "Confirm" style:uialertactionstyledefault
  58. handler:^ (uialertaction * _nonnull action) {
  59. NSLog (@ "---------");
  60. }];
  61. [VC addaction:action];
  62. [Self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil];
  63. });
  64. }
  65. }
  66. }];
  67. }
  68. }
  69. Else
  70. {
  71. NSLog (@ "Sorry, the system version is too Low");
  72. }
Copy Code

Summarize

The above is a small part of the introduction of the iOS development of the fingerprint of the simple introduction, I hope that we have some help, if you have any questions please give me a message, small series will promptly reply to you. Thank you very much for your support!

http://www.kmjdad.com/
http://www.jnsjzyy.com/
http://www.czhkwl.com/
http://www.express-o2o.com/
http://www.gzjindao.com/
http://www.chumingchuanmeiyishu.com/
http://www.thcxb.com/
http://www.xingguangkeji.com/
http://www.gdrhsy.com/
http://www.clhuiji.com/
http://www.nxjianye.com/
http://www.tjmingsheng.com/
http://www.gangguan022.com/
http://www.zyjbp.com/
http://www.qianhangmy.com/
http://www.tzminbell.com/

A brief introduction to fingerprint recognition in 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.