Touch ID簡單使用

實現iOS的指紋識別需要先

#import <LocalAuthentication/LocalAuthentication.h>


    LAContext *la =[[LAContext alloc] init];
    
    BOOL issupport = [la canEvaluatePolicy:kLAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL];

    la.localizedFallbackTitle = @"enter password"; // 驗證失敗後備選提示
    
    if (issupport) {
        
        
        [la evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"give me five" reply:^(BOOL success, NSError * _Nullable error) {
            
            
            if (success) {
                
                NSLog(@"驗證指紋成功");
            }else
            {
                
                NSLog(@"驗證指紋失敗error= %@ ",[error localizedDescription]);
                
                if (error.code == kLAErrorUserFallback) {
                    
                    NSLog(@"需要輸入密碼"); // 可以自己設置密碼比對
                }
                
            }
            
        }];
    }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章