iOS에서 Touch ID(지문인식) 사용하기.

posted on 05 Jul 2017 under category iOS

iOS에서 제공해주는 Touch-ID 간편하게 사용하기

  1. framework 추가하기

대체텍스트

  1. import 하기
    #import <LocalAuthentication/LocalAuthentication.h>
    
  2. Touch ID 사용가능 확인
    LAContext *context = [[LAContext alloc] init];
    NSError *error;
    if([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]){
     // 성공
    }else{
     // 실패
    }
    

    실패하는 경우

    • 디바이스에서 지문인식을 제공하지 않을 때
    • 디바이스에 암호가 설정되어있지 않을 경우
    • 등록된 지문이 없을 때
  3. 지문 확인
LAContext *context = [[LAContext alloc] init];
NSError *error;

    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"지문을 입력해주세요" reply:^(BOOL success, NSError *error){
        if(success){
            NSLog(@"@@@@성공");
        }else{
            NSLog(@"@@@@실패");
        }
    }];

실제 사용방법

LAContext *context = [[LAContext alloc] init];
NSError *error;
if([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]){
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"지문을 입력해주세요" reply:^(BOOL success, NSError *error){
        if(success){
            NSLog(@"@@@@성공"); // 지문 인증 성공했을때
        }else{
            NSLog(@"@@@@실패");
        }
    }];
}else{
    NSLog(@"Touch 지원하지 않음");
}
Written by Brody Byun
Please Do not steal content from our website.
Please let me know if you want to take the post.(email or reply)