-
-
Notifications
You must be signed in to change notification settings - Fork 848
Expand file tree
/
Copy pathAuthViewController.m
More file actions
54 lines (48 loc) · 2.03 KB
/
Copy pathAuthViewController.m
File metadata and controls
54 lines (48 loc) · 2.03 KB
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
48
49
50
51
52
53
54
//
// AuthViewController.m
// BHTwitter
//
// Created by BandarHelal on 25/09/2021.
//
#import "AuthViewController.h"
#import <LocalAuthentication/LocalAuthentication.h>
#import "keychain.h"
@interface AuthViewController ()
@end
@implementation AuthViewController
- (void)viewDidLoad {
[super viewDidLoad];
LAContext *context = [[LAContext alloc] init];
if ([self canEvaluateBiometrics]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"Touch ID or Face ID is required to use Twitter" reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
[[keychain shared] saveDictionary:@{@"isAuthenticated": @YES}];
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:true completion:nil];
});
} else {
[[keychain shared] saveDictionary:@{@"isAuthenticated": @NO}];
NSLog(@"%@", error);
}
}];
} else if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:nil]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:@"Passcode is required to use Twitter" reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
[[keychain shared] saveDictionary:@{@"isAuthenticated": @YES}];
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:true completion:nil];
});
} else {
[[keychain shared] saveDictionary:@{@"isAuthenticated": @NO}];
NSLog(@"%@", error);
}
}];
} else {
[[keychain shared] saveDictionary:@{@"isAuthenticated": @NO}];
}
}
- (BOOL)canEvaluateBiometrics {
NSMutableDictionary *infoPlistDict = [NSMutableDictionary dictionaryWithDictionary:[[NSBundle mainBundle] infoDictionary]];
return [infoPlistDict objectForKey:@"NSFaceIDUsageDescription"] != nil ? true : false;
}
@end