forked from Werbary/WBTouchID
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WBTouchID.m
43 lines (37 loc) · 1.27 KB
/
WBTouchID.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// PRTouchIdManager.m
// podRukoy
//
// Created by Иван Труфанов on 31.03.15.
// Copyright (c) 2015 Ratmanskiy Alexey. All rights reserved.
//
#import "WBTouchID.h"
@import LocalAuthentication;
NSString *const kWBTouchIdErrorDomain = @"WBTouchIdAuthenticationDomain";
@implementation WBTouchID
+ (BOOL) canUseTouchID {
if (NSClassFromString(@"LAContext") != nil) {
LAContext *context = [[LAContext alloc] init];
return [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL];
} else {
//iOS version not support Touch ID
return NO;
}
}
+ (void) validateTouchId:(TouchIdCallback)callback {
if (![self canUseTouchID]) {
callback(NO,[NSError errorWithDomain:kWBTouchIdErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"Touch ID isn't availiable"}]);
return;
}
LAContext *context = [[LAContext alloc] init];
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:kWBTouchIdReason reply:^(BOOL success, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
callback(YES,nil);
} else {
callback(NO,error);
}
});
}];
}
@end