iOS指紋解鎖后更新UI問題

昨天在公司需求中需要加入指紋解鎖功能

在指紋接受驗證后 ? 回調(diào)會在子線程中 ?因此需要調(diào)用主線程執(zhí)行ui更新 ??

然鵝群里一群人知道卻不告訴我 ? 害的我瞎忙活半天。。。。

代碼如下?

//初始化上下文對象

LAContext* context = [[LAContext alloc] init];

//錯誤對象

NSError* error = nil;

NSString* result = @"通過Home鍵驗證已有手機指紋";

//首先使用canEvaluatePolicy 判斷設(shè)備支持狀態(tài)

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {

//支持指紋驗證

[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:result reply:^(BOOL success, NSError *error) {

if (success) {

//驗證成功,主線程處理UI

[mUserdefaults setObject:@"1" forKey:isUseLock];

[mUserdefaults setObject:@"1" forKey:isOpenHand];

[mUserdefaults synchronize];

[SVProgressHUD showSuccessWithStatus:@"開啟成功"];

}

else

{

dispatch_async(dispatch_get_main_queue(), ^{

[mUserdefaults setObject:@"0" forKey:isOpenHand];

_sw.on = NO;

[SVProgressHUD dismiss];

});

NSLog(@"%@",error.localizedDescription);

switch (error.code) {

case LAErrorSystemCancel:

{

NSLog(@"Authentication was cancelled by the system");

//切換到其他APP,系統(tǒng)取消驗證Touch ID

break;

}

case LAErrorUserCancel:

{

NSLog(@"Authentication was cancelled by the user");

//用戶取消驗證Touch ID

break;

}

case LAErrorUserFallback:

{

NSLog(@"User selected to enter custom password");

[[NSOperationQueue mainQueue] addOperationWithBlock:^{

//用戶選擇其他驗證方式,切換主線程處理

}];

break;

}

default:

{

[[NSOperationQueue mainQueue] addOperationWithBlock:^{

//其他情況,切換主線程處理

}];

break;

}

}

}

}];

}

else

{

//不支持指紋識別,LOG出錯誤詳情

switch (error.code) {

case LAErrorTouchIDNotEnrolled:

{

NSLog(@"TouchID is not enrolled");

[SVProgressHUD showWithStatus:@"設(shè)備不支持指紋解鎖"];

break;

}

case LAErrorPasscodeNotSet:

{

[SVProgressHUD showWithStatus:@"設(shè)備未設(shè)置指紋解鎖"];

NSLog(@"A passcode has not been set");

break;

}

default:

{

[SVProgressHUD showWithStatus:@"設(shè)備未設(shè)置touchId"];

NSLog(@"TouchID not available");

break;

}

}

NSLog(@"%@",error.localizedDescription);

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容