file:///Users/OWen/Desktop/3DTouch.png
隨著iOS系統不斷的更新迭代,蘋果總會推出一些新的功能,今天就研究了一下iOS8之后推出的指紋驗證的功能,然后寫了一個小demo,與君分享。。
上demo: ? 1:首先導入一個系統的庫文件 ? ? ?#import <LocalAuthentication/LocalAuthentication.h>
? ? ? ? ? ? ? ? ?2:
? ??LAContext *mycontent = [[LAContext alloc] init];
?? ?
? ? NSString *myLocalizedReasonString = @"小伙子,請輸入你的指紋";
? ? NSError *authError = nil;
?
? ? if ([mycontent canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
?? ? ? ?
? ? ? ? [mycontent evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
? ? ? ? ?
? ? ? ? ? ? ? ? ? localizedReason:myLocalizedReasonString
? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? reply:^(BOOL success, NSError *error) {
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (success) {
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // User authenticated successfully, take appropriate action
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } else {
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"-----%@",error);
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // User did not authenticate successfully, look at error and take appropriate action
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? }];
?? ? ? ?
? ? } else {
? ? ? ? // Could not evaluate policy; look at authError and present an appropriate message to user
? ? }
?注意,測試神馬的還得在真機上調試。