IOS 指紋識別兩種方式詳解及實例
首先引入類名:
#import <LocalAuthentication/LocalAuthentication.h>
然后在實現指紋識別的地方放入如下代碼:
方式一:
LAContext *lacontext = [[LAContext alloc]init]; // 判斷設備是否支持指紋識別 BOOL isSupport = [lacontext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL]; if(!isSupport) { NSLog(@"不支持!"); return; } [lacontext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"請按下手印" reply:^(BOOL success, NSError *error) { if(success) { NSLog(@"成功后,處理接下來的邏輯"); } }];
iPhone 5s推出指紋識別, 在 iOS 8.0 蘋果開放了指紋識別的 SDK
最重要的應用領域是支付
方式二:
if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) { NSLog(@"不支持"); return; } LAContext *ctx = [[LAContext alloc] init]; // 判斷設備是否支持指紋識別 if ([ctx canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL]) { NSLog(@"支持"); // 輸入指紋,異步 // 提示:指紋識別只是判斷當前用戶是否是手機的主人!程序原本的邏輯不會受到任何的干擾! [ctx evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"指紋登錄" reply:^(BOOL success, NSError *error) { if (success) { // 登錄成功 // TODO NSLog(@"登陸成功"); } }]; } else { NSLog(@"不支持"); }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答