-
Notifications
You must be signed in to change notification settings - Fork 380
/
SecurityViewController.m
47 lines (37 loc) · 1.57 KB
/
SecurityViewController.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
44
45
46
47
#import "SecurityViewController.h"
@implementation SecurityViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurView.frame = self.view.bounds;
[self.view addSubview:blurView];
UIButton *authenticateButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 20, 200, 60)];
[authenticateButton setTitle:@"Authenticate" forState:UIControlStateNormal];
authenticateButton.center = self.view.center;
[authenticateButton addTarget:self action:@selector(authenticateButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:authenticateButton];
[self authenticate];
}
- (void)authenticateButtonTapped:(id)sender {
[self authenticate];
}
- (void)authenticate {
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&error]) {
NSString *reason = @"Identify yourself!";
[context evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:reason reply:^(BOOL success, NSError *authenticationError) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
[self dismissViewControllerAnimated:YES completion:nil];
} else {
// error
}
});
}];
} else {
// no biometry
}
}
@end