Skip to content

Commit ae2c0ea

Browse files
committed
Updated for Face ID
1 parent dca58f5 commit ae2c0ea

17 files changed

+127
-95
lines changed

Demo/LTHPasscodeViewController Demo/LTHDemoViewController.m

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ @interface LTHDemoViewController () <LTHPasscodeViewControllerDelegate, UITextFi
2121
@property (nonatomic, strong) UITextField *digitsTextField;
2222
@property (nonatomic, strong) UILabel *typeLabel;
2323
@property (nonatomic, strong) UISwitch *typeSwitch;
24-
@property (nonatomic, strong) UILabel *touchIDLabel;
25-
@property (nonatomic, strong) UISwitch *touchIDSwitch;
24+
@property (nonatomic, strong) UILabel *biometricsLabel;
25+
@property (nonatomic, strong) UISwitch *biometricsSwitch;
2626
@end
2727

2828

@@ -55,7 +55,7 @@ - (void)_refreshUI {
5555

5656
_digitsTextField.text = [NSString stringWithFormat:@"%zd", [LTHPasscodeViewController sharedUser].digitsCount];
5757
_typeSwitch.on = [[LTHPasscodeViewController sharedUser] isSimple];
58-
_touchIDSwitch.on = [[LTHPasscodeViewController sharedUser] allowUnlockWithTouchID];
58+
_biometricsSwitch.on = [[LTHPasscodeViewController sharedUser] allowUnlockWithBiometrics];
5959
}
6060

6161
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
@@ -83,15 +83,27 @@ - (void)viewDidLoad {
8383
_changePasscode.frame = CGRectMake(100, 300, 100, 50);
8484
_turnOffPasscode.frame = CGRectMake(100, 400, 100, 50);
8585

86-
if ([self isTouchIDAvailable]) {
86+
if ([self areBiometricsAvailable]) {
8787
_typeLabel = [[UILabel alloc] initWithFrame:(CGRect){230, 190, 60, 30}];
8888
_typeSwitch = [[UISwitch alloc] initWithFrame:(CGRect){230, 220, 100, 100}];
89-
_touchIDLabel = [[UILabel alloc] initWithFrame:(CGRect){230, 290, 90, 30}];
90-
_touchIDSwitch = [[UISwitch alloc] initWithFrame:(CGRect){230, 320, 100, 100}];
91-
_touchIDLabel.text = @"Touch ID";
92-
[_touchIDSwitch addTarget:self action:@selector(_touchIDPasscodeType:) forControlEvents:UIControlEventValueChanged];
93-
[self.view addSubview:_touchIDSwitch];
94-
[self.view addSubview:_touchIDLabel];
89+
_biometricsLabel = [[UILabel alloc] initWithFrame:(CGRect){230, 290, 90, 30}];
90+
_biometricsSwitch = [[UISwitch alloc] initWithFrame:(CGRect){230, 320, 100, 100}];
91+
92+
_biometricsLabel.text = @"Touch ID";
93+
94+
LAContext *context = [[LAContext alloc] init];;
95+
96+
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
97+
if (@available(iOS 11.0, *)) {
98+
if (context.biometryType == LABiometryTypeFaceID) {
99+
self.biometricsLabel.text = @"Face ID";
100+
}
101+
}
102+
}
103+
104+
[_biometricsSwitch addTarget:self action:@selector(_touchIDPasscodeType:) forControlEvents:UIControlEventValueChanged];
105+
[self.view addSubview:_biometricsSwitch];
106+
[self.view addSubview:_biometricsLabel];
95107
} else {
96108
_typeLabel = [[UILabel alloc] initWithFrame:(CGRect){230, 230, 60, 30}];
97109
_typeSwitch = [[UISwitch alloc] initWithFrame:(CGRect){230, 260, 100, 100}];
@@ -186,7 +198,7 @@ - (void)_switchPasscodeType:(UISwitch *)sender {
186198
}
187199

188200
- (void)_touchIDPasscodeType:(UISwitch *)sender {
189-
[[LTHPasscodeViewController sharedUser] setAllowUnlockWithTouchID:sender.isOn];
201+
[[LTHPasscodeViewController sharedUser] setAllowUnlockWithBiometrics:sender.isOn];
190202
}
191203

192204
- (void)showLockViewForEnablingPasscode {
@@ -214,7 +226,7 @@ - (void)showLockViewForTurningPasscodeOff {
214226
asModal:NO];
215227
}
216228

217-
- (BOOL)isTouchIDAvailable {
229+
- (BOOL)areBiometricsAvailable {
218230
if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending) {
219231
return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
220232
}

LTHPasscodeViewController/LTHPasscodeViewController.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@
7777
*/
7878
- (NSString *)passcode;
7979
/**
80-
@brief Handle here the saving of the preference for allowing the use of TouchID.
80+
@brief Handle here the saving of the preference for allowing the use of Biometrics.
8181
@details Called if @c +useKeychain:NO was used, but falls back to the Keychain anyway if not implemented.
82-
@param allowUnlockWithTouchID The boolean for the preference for allowing the use of TouchID.
82+
@param allowUnlockWithBiometrics The boolean for the preference for allowing the use of Biometrics.
8383
*/
84-
- (void)saveAllowUnlockWithTouchID:(BOOL)allowUnlockWithTouchID;
84+
- (void)saveAllowUnlockWithBiometrics:(BOOL)allowUnlockWithBiometrics;
8585
/**
86-
@brief Retrieve here the saved preference for allowing the use of TouchID.
86+
@brief Retrieve here the saved preference for allowing the use of Biometrics.
8787
@details Called if @c +useKeychain:NO was used, but falls back to the Keychain anyway if not implemented.
88-
@return allowUnlockWithTouchID boolean.
88+
@return allowUnlockWithBiometrics boolean.
8989
*/
90-
- (BOOL)allowUnlockWithTouchID;
90+
- (BOOL)allowUnlockWithBiometrics;
9191
@end
9292

9393
@interface LTHPasscodeViewController : UIViewController
@@ -209,9 +209,9 @@
209209
*/
210210
@property (nonatomic, strong) NSString *keychainServiceName;
211211
/**
212-
@brief The string to be used as username for allow TouchID unlock in the Keychain.
212+
@brief The string to be used as username for allow Biometrics unlock in the Keychain.
213213
*/
214-
@property (nonatomic, strong) NSString *keychainAllowUnlockWithTouchID;
214+
@property (nonatomic, strong) NSString *keychainAllowUnlockWithBiometrics;
215215
/**
216216
@brief The character for the passcode digit.
217217
*/
@@ -266,9 +266,10 @@
266266
*/
267267
@property (nonatomic, strong) NSString *reenterNewPasscodeString;
268268
/**
269-
@brief The string displayed while user unlocks with TouchID.
269+
@brief The string displayed while user unlocks with Biometrics.
270+
@details Do not forget to test what kind of Biometrics the device is using, and display the correct string. (Touch ID vs Face ID, for example)
270271
*/
271-
@property (nonatomic, strong) NSString *touchIDString;
272+
@property (nonatomic, strong) NSString *biometricsDetailsString;
272273
/**
273274
@brief The duration of the lock animation.
274275
*/
@@ -300,9 +301,9 @@
300301
@property (nonatomic, assign) BOOL hidesCancelButton;
301302

302303
/**
303-
@brief A Boolean value that indicates whether TouchID can be used (@c YES) or not (@c NO). Default is @c YES.
304+
@brief A Boolean value that indicates whether Biometrics can be used (@c YES) or not (@c NO). Default is @c YES.
304305
*/
305-
@property (nonatomic, assign) BOOL allowUnlockWithTouchID;
306+
@property (nonatomic, assign) BOOL allowUnlockWithBiometrics;
306307

307308

308309
// MARK: - Methods

0 commit comments

Comments
 (0)