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