-
-
Save ydzheng/34ff7724d77cb41b6e24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)canUseTouchID:(NSError *__autoreleasing *)error { | |
BOOL canEvaluate = NO; | |
NSError *localError = nil; | |
NSError *authError = nil; | |
if (!_localAuthContext) { | |
_localAuthContext = [[LAContext alloc] init]; | |
} | |
if ([_localAuthContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { | |
canEvaluate = YES; | |
localError = nil; | |
} else { | |
if (authError.code == LAErrorPasscodeNotSet) { | |
localError = [NSError errorWithDomain:WFTouchIDErrorDomain | |
code:WFTouchIDPasscodeNotSet | |
userInfo:authError.userInfo]; | |
} else if (authError.code == LAErrorTouchIDNotEnrolled) { | |
localError = [NSError errorWithDomain:WFTouchIDErrorDomain | |
code:WFTouchIDTouchIDNotEnrolled | |
userInfo:authError.userInfo]; | |
} else { | |
localError = [NSError errorWithDomain:WFTouchIDErrorDomain | |
code:WFTouchIDNotAvailable | |
userInfo:@{@"info" : @"TouchID not available."}]; | |
} | |
} | |
BOOL optOutTouchID = ![_userDefaultsManager touchIDChoice]; | |
if (canEvaluate && optOutTouchID) { | |
canEvaluate = NO; | |
localError = [NSError errorWithDomain:WFTouchIDErrorDomain | |
code:WFTouchIDOptOut | |
userInfo:@{@"info" : @"User opt out of TouchID."}]; | |
} | |
if (canEvaluate == NO) { | |
WF_CHECK_ASSIGN_ERROR(error, localError); | |
} | |
return canEvaluate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment