iOS Touch ID 使用詳情

來源:互聯網
上載者:User

標籤:

簡單介紹:

支援系統和機型

       iOS系統的指紋識別功能最低支援的機型為iPhone 5s,最低支援系統為iOS 8,雖然安裝iOS 7系統的5s機型可以使用系統提供的指紋解鎖功能,但由於API並未開放,所以理論上第三方軟體不可使用。

依賴架構
LocalAuthentication.framework
import <LocalAuthentication/LocalAuthentication.h>

注意事項
做iOS 8以下版本適配時,務必進行API驗證,避免調用相關API引起崩潰。

使用類
LAContext
指紋驗證操作對象


代碼實現:

//初始化內容物件    LAContext* context = [[LAContext alloc] init];    //錯誤對象    NSError  * error = nil;    NSString * result = @"驗證";    context.localizedFallbackTitle = @"123";       //判斷裝置是否支援touchID    BOOL isSupport = [context canEvaluatePolicy:    LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];    if (isSupport) {        //指紋識別函數        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics         localizedReason:@"用 Touch ID 登入"         reply:^(BOOL success, NSError *error) {          //如果成功            if (success) {                NSLog(@"驗證成功");            }else{                switch (error.code) {                    case LAErrorSystemCancel:                    {                        NSLog(@"Authentication was cancelled by the system");                        //切換到其他APP,系統取消驗證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;                    }                }            }        }];} else {  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);}
下面是LAError中每個枚舉對應的含義

typedef NS_ENUM(NSInteger, LAError){ //授權失敗        LAErrorAuthenticationFailed = kLAErrorAuthenticationFailed,         //使用者取消Touch ID授權       LAErrorUserCancel           = kLAErrorUserCancel,         //使用者選擇輸入密碼         LAErrorUserFallback         = kLAErrorUserFallback,         //系統取消授權(例如其他APP切入)        LAErrorSystemCancel         = kLAErrorSystemCancel,         //系統未設定密碼        LAErrorPasscodeNotSet       = kLAErrorPasscodeNotSet,         //裝置Touch ID不可用,例如未開啟     LAErrorTouchIDNotAvailable  = kLAErrorTouchIDNotAvailable,         //裝置Touch ID不可用,使用者未錄入     LAErrorTouchIDNotEnrolled   = kLAErrorTouchIDNotEnrolled,}



iOS Touch ID 使用詳情

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.