iOS 之(個人隱私錢包調用系統TouchID指紋鎖驗證)

來源:互聯網
上載者:User

標籤:

//

//  ViewController.m

//  TouchID指紋驗證

//

//  Created by apple on 16/9/18.

//  Copyright © 2016年 apple. All rights reserved.

//

 

#import "ViewController.h"

#import "HomeViewController.h"//跳轉成功後需要跳轉到的視圖控制器

#import <LocalAuthentication/LocalAuthentication.h>//匯入TouchID需要的類庫

#import <sys/utsname.h> //擷取裝置基本資料需要的類庫

@interface ViewController ()

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

 

    [self touchID];

}

 

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    //調用TouchID會執行此方法,有需要可以實現一些另外的功能

}

 

- (void)touchID {

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

    NSError *error = nil;

    // 第一步判斷是否支援Touch ID 或者 本機是否已經錄入指紋

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

        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"請驗證已有指紋" reply:^(BOOL success, NSError * _Nullable error) {

            if (error) {

                NSLog(@"驗證失敗"); // 系統會自動給錯誤提示

            }else{

                dispatch_async(dispatch_get_main_queue(), ^{

                    // 指紋驗證成功後跳轉

                    HomeViewController *home = [[HomeViewController alloc] init];

                    [self presentViewController:home animated:YES completion:nil];

                });

            }

        }];

    }else {

        // 判斷是否真機運行

        if (self.isSimulator) {

            [[[UIAlertView alloc] initWithTitle:@"提示" message:@"請用真機測試~" delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil] show];

        }else{

            [[[UIAlertView alloc] initWithTitle:@"提示" message:@"不支援Touch ID~" delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil] show];

        }

    }

}

// 判斷當前裝置是否支援TouchID功能

- (BOOL)isSimulator{

    struct utsname systemInfo;

    uname(&systemInfo);

    NSString *deviceMachine = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];

    if ([deviceMachine isEqualToString:@"i386"] || [deviceMachine isEqualToString:@"x86_64"])       {

        return YES;

    }

    return NO;

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

 

@end

iOS 之(個人隱私錢包調用系統TouchID指紋鎖驗證)

聯繫我們

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