@@ -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 }
0 commit comments