IOS iPhone X Face ID

好久沒過來,小知識知識,預(yù)祝大家清明節(jié)快樂

iPhone X 已經(jīng)出來一段時間了,雖然面部識別很高大上,但是小白我還是買不起啊,一直沒有體會到那種裝B的感覺,我看到支付寶,微信都用系統(tǒng)自帶的Face ID進(jìn)行支付認(rèn)證,于是我就研究下了(借朋友的手機(jī)、可憐)

其實很簡單基本和Tounch ID一個樣子,不說沒用的啦 直接上代碼

記住要添加頭文件

#import <LocalAuthentication/LocalAuthentication.h>

??? if (@available(iOS 8.0, *)) {
??????? LAContext *context = [[LAContext alloc] init];
???????
??????? NSString *typeString = @"";

??????? if (@available(iOS 11.0, *)) {
??????????? if (context.biometryType == LABiometryTypeTouchID) {
??????????????? typeString = @"指紋登錄";
??????????? }else if (context.biometryType == LABiometryTypeFaceID){
??????????????? typeString = @"Face ID登錄";
??????????? }
??????? } else {
??????? }
???????
??????? [self loginType:typeString withContent:context];
??? }else {?
??????? NSLog(@"你的設(shè)備不支持指紋識別");?????
??? }

- (void)loginType:(NSString *)type withContent:(LAContext *)context{

??? 檢驗是否系統(tǒng)支持FaceID

? ? if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {

?????? 驗證FaceID是否通過

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

? ? ? ? ? ? if (success) {


? ? ? ? ? ? ? ? UIAlertController *con = [UIAlertController alertControllerWithTitle:@"提示" message:type preferredStyle:(UIAlertControllerStyleAlert)];

? ? ? ? ? ? ? ? UIAlertAction *alt1 = [UIAlertAction actionWithTitle:@"確定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {

? ? ? ? ? ? ? ? }];

? ? ? ? ? ? ? ? [con addAction:alt1];

? ? ? ? ? ? ? ? [self presentViewController:con animated:YES completion:nil];


? ? ? ? ? ? }else{


? ? ? ? ? ? ? ? UIAlertController *con = [UIAlertController alertControllerWithTitle:@"提示" message:type preferredStyle:(UIAlertControllerStyleAlert)];

? ? ? ? ? ? ? ? UIAlertAction *alt1 = [UIAlertAction actionWithTitle:@"失敗" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {


? ? ? ? ? ? ? ? }];

? ? ? ? ? ? ? ? [con addAction:alt1];

? ? ? ? ? ? ? ? [self presentViewController:con animated:YES completion:nil];

? ? ? ? ? ? }

? ? ? ? }];

? ? }

}

是不是很簡單,希望你們早點用上這個功能。每天一小步,加油!?。?/h4>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容