Skip to content

Instantly share code, notes, and snippets.

@ydzheng
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ydzheng/34ff7724d77cb41b6e24 to your computer and use it in GitHub Desktop.
Save ydzheng/34ff7724d77cb41b6e24 to your computer and use it in GitHub Desktop.
- (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