From e17f1110267145987fc7e6b0ae252364e0e2e4b7 Mon Sep 17 00:00:00 2001 From: Dasmer Singh Date: Sat, 10 Jan 2015 10:57:05 -0500 Subject: [PATCH 1/2] Add static BOOL isTouchIDPresented so LAContext is never invoked more than once at a time --- VENTouchLock/VENTouchLock.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/VENTouchLock/VENTouchLock.m b/VENTouchLock/VENTouchLock.m index 99a5403..0348f25 100644 --- a/VENTouchLock/VENTouchLock.m +++ b/VENTouchLock/VENTouchLock.m @@ -127,12 +127,15 @@ - (void)requestTouchIDWithCompletion:(void (^)(VENTouchLockTouchIDResponse))comp - (void)requestTouchIDWithCompletion:(void (^)(VENTouchLockTouchIDResponse))completionBlock reason:(NSString *)reason { - if ([[self class] canUseTouchID]) { + 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) { From f27ca6668f8059e931cd6f2da742441c03bdb6fd Mon Sep 17 00:00:00 2001 From: Dasmer Singh Date: Mon, 12 Jan 2015 10:16:39 -0500 Subject: [PATCH 2/2] Create VENTouchLockTouchIDResponsePromptAlreadyPresent --- VENTouchLock/VENTouchLock.h | 1 + VENTouchLock/VENTouchLock.m | 45 +++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/VENTouchLock/VENTouchLock.h b/VENTouchLock/VENTouchLock.h index a9ef20d..1c13626 100644 --- a/VENTouchLock/VENTouchLock.h +++ b/VENTouchLock/VENTouchLock.h @@ -9,6 +9,7 @@ typedef NS_ENUM(NSUInteger, VENTouchLockTouchIDResponse) { VENTouchLockTouchIDResponseSuccess, VENTouchLockTouchIDResponseUsePasscode, VENTouchLockTouchIDResponseCanceled, + VENTouchLockTouchIDResponsePromptAlreadyPresent, }; @interface VENTouchLock : NSObject diff --git a/VENTouchLock/VENTouchLock.m b/VENTouchLock/VENTouchLock.m index 0348f25..0280dae 100644 --- a/VENTouchLock/VENTouchLock.m +++ b/VENTouchLock/VENTouchLock.m @@ -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: @@ -156,11 +156,18 @@ - (void)requestTouchIDWithCompletion:(void (^)(VENTouchLockTouchIDResponse))comp response = VENTouchLockTouchIDResponseUndefined; break; } - completionBlock(response); + if (completionBlock) { + completionBlock(response); + } } - } - }); - }]; + }); + }]; + } + else { + if (completionBlock) { + completionBlock(VENTouchLockTouchIDResponsePromptAlreadyPresent); + } + } } }