2017-02-11 95 views

回答

-1

如果您想在越獄設備上使用私人BiometricKit框架,我無法真正幫助您......
如果您只想利用TouchID功能,您只需要使用公共LocalAuthentication框架。

下面是一個Objective-C中一個非常基本實現假裝MyViewControllerUIViewController子類(您最終可能要移動的邏輯離開那裏):

#import "MyViewController.h" 
@import LocalAuthentication; 

@interface MyViewController() 
@property (nonatomic, strong) LAContext *localAuthContext; 
@end 


@implementation MyViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self authenticateWithTouchID]; // Call this whenever TouchID authentication is required. 
} 

#pragma mark - TouchID Authentication 

- (void)authenticateWithTouchID { 
    NSError *evaluationError; 
    if (![self.localAuthContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&evaluationError]) { 
     // TODO: Handle error case. (device with no TouchID capability) 
     NSLog(@"%@", evaluationError.localizedDescription); 
    } else { 
     [self.localAuthContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
           localizedReason:@"Authenticate using Touch ID" 
             reply:^(BOOL success, NSError *error) { 

              if (!success) { 
               // TODO: Handle error case. (failed TouchID authentication) 
               NSLog(@"%@", error.localizedDescription); 
              } else { 
               // TODO: Handle success case. 
               NSLog(@"TouchID authentication successful."); 
              } 
             }]; 
    } 
} 

#pragma mark - Lazy Instantiation 

- (LAContext *)localAuthContext 
{ 
    if (!_localAuthContext) { 
     _localAuthContext = [[LAContext alloc] init]; 
     _localAuthContext.localizedFallbackTitle = @""; // Hides the "Enter Password" button. Comment out to allow the user to enter his device passcode as a fallback option. 
    } 
    return _localAuthContext; 
} 

@end 

首先確保你有一個指紋設置在您的設備上(設置>觸摸ID &密碼>指紋部分)。

相關問題