Skip to content

Commit

Permalink
Merge pull request #31 from venmo/daz/fix_freeze
Browse files Browse the repository at this point in the history
Prevent LAContext evaluatePolicy:localizedReason:reply: from being invoked multiple times
  • Loading branch information
eliperkins committed Jan 13, 2015
2 parents e9aa74d + f27ca66 commit 520d182
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions VENTouchLock/VENTouchLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ typedef NS_ENUM(NSUInteger, VENTouchLockTouchIDResponse) {
VENTouchLockTouchIDResponseSuccess,
VENTouchLockTouchIDResponseUsePasscode,
VENTouchLockTouchIDResponseCanceled,
VENTouchLockTouchIDResponsePromptAlreadyPresent,
};

@interface VENTouchLock : NSObject
Expand Down
42 changes: 26 additions & 16 deletions VENTouchLock/VENTouchLock.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,23 @@ - (void)requestTouchIDWithCompletion:(void (^)(VENTouchLockTouchIDResponse))comp

- (void)requestTouchIDWithCompletion:(void (^)(VENTouchLockTouchIDResponse))completionBlock reason:(NSString *)reason
{
static BOOL isTouchIDPresented = NO;
if ([[self class] canUseTouchID]) {
LAContext *context = [[LAContext alloc] init];
context.localizedFallbackTitle = NSLocalizedString(@"Enter Passcode", nil);
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:reason
reply:^(BOOL success, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
if (completionBlock) {
completionBlock(VENTouchLockTouchIDResponseSuccess);
if (!isTouchIDPresented) {
isTouchIDPresented = YES;
LAContext *context = [[LAContext alloc] init];
context.localizedFallbackTitle = NSLocalizedString(@"Enter Passcode", nil);
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:reason
reply:^(BOOL success, NSError *error) {
isTouchIDPresented = NO;
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
if (completionBlock) {
completionBlock(VENTouchLockTouchIDResponseSuccess);
}
}
}
else {
if (completionBlock) {
else {
VENTouchLockTouchIDResponse response;
switch (error.code) {
case LAErrorUserFallback:
Expand All @@ -153,11 +156,18 @@ - (void)requestTouchIDWithCompletion:(void (^)(VENTouchLockTouchIDResponse))comp
response = VENTouchLockTouchIDResponseUndefined;
break;
}
completionBlock(response);
if (completionBlock) {
completionBlock(response);
}
}
}
});
}];
});
}];
}
else {
if (completionBlock) {
completionBlock(VENTouchLockTouchIDResponsePromptAlreadyPresent);
}
}
}
}

Expand Down

0 comments on commit 520d182

Please sign in to comment.