IOS開發-指紋識別

來源:互聯網
上載者:User

標籤:ios   指紋識別   

1. 簡介
  • iPhone 5S 開始支援
  • iOS 8.0 開放了 Touch ID 的介面
2. 代碼準備
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {    [self inputUserinfo];}///  輸入使用者資訊- (void)inputUserinfo {    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"購買" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"購買", nil];    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;    [alertView show];}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {    NSLog(@"%zd", buttonIndex);    if (buttonIndex == 0) {        return;    }    UITextField *usernameText = [alertView textFieldAtIndex:0];    UITextField *pwdText = [alertView textFieldAtIndex:1];    if ([usernameText.text isEqualToString:@"zhang"] && [pwdText.text isEqualToString:@"123"]) {        [self purchase];    } else {        [[[UIAlertView alloc] initWithTitle:@"提示" message:@"使用者名稱或密碼錯誤" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil] show];    }}///  購買- (void)purchase {    NSLog(@"購買");}
3. 指紋識別標頭檔
#import <LocalAuthentication/LocalAuthentication.h>
判斷是否支援指紋識別
// 檢查版本if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {    [self inputUserinfo];    return;}// 檢查是否支援指紋識別LAContext *ctx = [[LAContext alloc] init];if ([ctx canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL]) {    NSLog(@"支援指紋識別");    // 非同步輸入指紋    [ctx evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"購買" reply:^(BOOL success, NSError *error) {        NSLog(@"%d %@ %@", success, error, [NSThread currentThread]);        if (success) {            [self purchase];        } else if (error.code == LAErrorUserFallback) {            dispatch_async(dispatch_get_main_queue(), ^{                [self inputUserinfo];            });        }    }];    NSLog(@"come here");} else {    [self inputUserinfo];}
4. 錯誤代號
錯誤 描述
LAErrorAuthenticationFailed 指紋無法識別
LAErrorUserCancel 使用者點擊了”取消”按鈕
LAErrorUserFallback 使用者取消,點擊了”輸入密碼”按鈕
LAErrorSystemCancel 系統取消,例如啟用了其他應用程式
LAErrorPasscodeNotSet 驗證無法啟動,因為裝置上沒有設定密碼
LAErrorTouchIDNotAvailable 驗證無法啟動,因為裝置上沒有 Touch ID
LAErrorTouchIDNotEnrolled 驗證無法啟動,因為沒有輸入指紋

IOS開發-指紋識別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.