http://blog.csdn.net/hongfengkt/article/details/49868073
A while ago has been in the progress of the project, not too much time to write a blog, now finally free, the previous owed to the blog to fill up.
After iOS8.0, the API opens up the functionality of fingerprint verification. Although the open API can only be used as a validation, it is more restrictive, but it is sufficient for apps with similar "gesture password" functionality. With this new API, you can unlock a large number of apps in the app.
The minimum hardware support for the Fingerprint verification feature is Iphone5s,ipad 6,ipad Mini 3 These devices with Touch ID hardware support, and the operating system is at least iOS8.0, because Touch ID is a class of APIs that are open after iOS8.0.
Put the code below.
When you do iOS8.0 the next version, be sure to validate the API to avoid invoking the associated API to cause a crash.
To introduce a dependent framework:
#import <LocalAuthentication/LocalAuthentication.h>
Implementation of fingerprint verification
- (void) authenticateuser{Initializes the context object lacontext* contextual = [[Lacontext alloc] init];Error Objectnserror* error =Nilnsstring* result = @"Authentication is needed to access your notes.";First use Canevaluatepolicy to determine the device support statusif ([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:&error]) {Fingerprint verification supported [context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Localizedreason:result reply:^ (BOOL Success,Nserror *error) {if (success) {Validation successful, main thread processing UI}else {NSLog (@"%@", error. localizeddescription);Switch (Error. Code) {Case Laerrorsystemcancel: {NSLog (@"Authentication is cancelled by the system");Switch to another app, the system cancels the verification touch IDBreak }Case Laerrorusercancel: {NSLog (@"Authentication is cancelled by the user");User cancels authentication Touch IDBreak }Case Laerroruserfallback: {NSLog (@"User selected to enter custom password"); [[Nsoperationqueue Mainqueue] addoperationwithblock:^{The user chooses another authentication method, switches the main thread processing}];Break }Default: {[[Nsoperationqueue Mainqueue] addoperationwithblock:^{Other cases, switch main thread processing}];Break } } } }]; }else {//Does not support fingerprint identification, log out error details switch (Error. Code) {Case laerrortouchidnotenrolled: { NSLog (@"TouchID) Not enrolled "); Break ;} Case Laerrorpasscodenotset: { NSLog (@"A passcode have not been set"); Break ;} default: { NSLog (@"TouchID not Available"); Break ;} } NSLog (@"%@", error. localizeddescription); [SelfShowpasswordalert];}}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
A description of several situations
typedef ns_enum ( nsinteger, Laerror) {//authorization failed laerrorauthenticationfailed = klaerrorauthenticationfailed, //user cancels Touch ID authorization laerrorusercancel = klaerrorusercancel, //user selected input password L Aerroruserfallback = Klaerroruserfallback, //system de-authorization (e.g. other app cut-in) Laerrorsystemcancel = Klaerrorsystemcancel, //system not set password Laerrorpasscodenotset = Klaerrorpasscodenotset, //device Touch ID is not available, for example not turned on laerrortouchidnotavailable = klaerrortouchidnotavailable, //device Touch ID not available, user not input laerrortouchidnotenrolled = klaerrortouchidnotenrolled,} ns_enum_available ( Span class= "Hljs-number" >10_10, 8_0);
Fingerprint unlocking for iOS development