1、首先,引入依賴框架 LocalAuthentication.framework
#import <LocalAuthentication/LocalAuthentication.h>
2、然後,判斷系統是否為IOS8及以上
//IOS8.0後才支持指紋識別接口
if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {
return;
}
3、最後,在APP啟動時調用以下方法即可完成指紋解鎖的全部功能集成
- (void)evaLuateAuthenticate
{
//創建LAContext
LAContext* context = [[LAContext alloc] init];
NSError* error = nil;
NSString* result = @"請驗證已有指紋";
//首先使用canEvaLuatePolicy 判斷設備支持狀態
if ([context canEvaLuatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
//支持指紋驗證
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:result reply:^(BOOL success, NSError *error) {
if (success) {
//驗證成功,主線程處理UI
}
else
{
NSLog(@"%@",error.localizedDescription);
switch (error.code) {
case LAErrorSystemCancel:
{
//系統取消授權,如其他APP切入
break;
}
case LAErrorUserCancel:
{
//用戶取消驗證Touch ID
break;
}
case LAErrorAuthenticationFailed:
{
//授權失敗
break;
}
case LAErrorPasscodeNotSet:
{
//系統未設置密碼
break;
}
case LAErrorTouchIDNotAvailable:
{
//設備Touch ID不可用,例如未打開
break;
}
case LAErrorTouchIDNotEnrolled:
{
//設備Touch ID不可用,用戶未錄入
break;
}
case LAErrorUserFallback:
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//用戶選擇輸入密碼,切換主線程處理
}];
break;
}
default:
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//其他情況,切換主線程處理
}];
break;
}
}
}
}];
}
else
{
//不支持指紋識別,LOG出錯誤詳情
NSLog(@"不支持指紋識別");
switch (error.code) {
case LAErrorTouchIDNotEnrolled:
{
NSLog(@"TouchID is not enrolled");
break;
}
case LAErrorPasscodeNotSet:
{
NSLog(@"A passcode has not been set");
break;
}
default:
{
NSLog(@"TouchID not available");
break;
}
}
NSLog(@"%@",error.localizedDescription);
}
}
【iOS 指紋解鎖 驗證TouchID】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!