Skip to content

Commit

Permalink
Create VENTouchLockTouchIDResponsePromptAlreadyPresent
Browse files Browse the repository at this point in the history
  • Loading branch information
Dasmer Singh committed Jan 12, 2015
1 parent e17f111 commit f27ca66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 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
45 changes: 26 additions & 19 deletions VENTouchLock/VENTouchLock.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,22 @@ - (void)requestTouchIDWithCompletion:(void (^)(VENTouchLockTouchIDResponse))comp
- (void)requestTouchIDWithCompletion:(void (^)(VENTouchLockTouchIDResponse))completionBlock reason:(NSString *)reason
{
static BOOL isTouchIDPresented = NO;
if ([[self class] canUseTouchID] && !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);
if ([[self class] canUseTouchID]) {
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 @@ -156,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 f27ca66

Please sign in to comment.