From 5308dbe359fe7621ef0e88688bd4d5e5cf6f3c38 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 14 Oct 2016 08:29:53 +0200 Subject: [PATCH 1/3] Add time frame to lock --- VENTouchLock/VENTouchLock.h | 15 +++++++++++++-- VENTouchLock/VENTouchLock.m | 22 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/VENTouchLock/VENTouchLock.h b/VENTouchLock/VENTouchLock.h index 642ee90..9c853a8 100644 --- a/VENTouchLock/VENTouchLock.h +++ b/VENTouchLock/VENTouchLock.h @@ -95,13 +95,24 @@ typedef NS_ENUM(NSUInteger, VENTouchLockTouchIDResponse) { /** If a passcode is set, calling this method will lock the app. Otherwise, calling it will not do anything. - @note The app is automatically locked when on launch and on entering background. Use this method only if necessary in other circumstances. + @note The app is automatically locked if needed (see method below) when on launch and on entering background. Use this method only if necessary in other circumstances. */ - (void)lock; +/** + Locks the app if has passed 'secondsToLock' from 'lastRefreshDate'. Otherwile, calling it will not do anything. + */ +- (void) lockIfNeeded; + + /** @return The proxy for the receiver's user interface. Custom appearance preferences may optionally be set by editing the returned instance's properties. */ - (VENTouchLockAppearance *)appearance; -@end \ No newline at end of file +/** +Updates de refreshDate value with current date +*/ +- (void) updateRefreshDate; + +@end diff --git a/VENTouchLock/VENTouchLock.m b/VENTouchLock/VENTouchLock.m index a6272e8..0e33552 100644 --- a/VENTouchLock/VENTouchLock.m +++ b/VENTouchLock/VENTouchLock.m @@ -15,6 +15,8 @@ @interface VENTouchLock () @property (assign, nonatomic) Class splashViewControllerClass; @property (strong, nonatomic) UIView *snapshotView; @property (strong, nonatomic) VENTouchLockAppearance *appearance; +@property (nonatomic) NSInteger secondsToLock; +@property (strong, nonatomic) NSDate* lastRefreshDate; @end @@ -217,18 +219,34 @@ - (void)lock } } +- (void) lockIfNeeded { + if (_lastRefreshDate) { + if (fabsf([_lastRefreshDate timeIntervalSinceNow]) >= _secondsToLock) { + [self lock]; + } + } else { + [self lock]; + } +} + +#pragma mark - Refresh date methods + +- (void) updateRefreshDate { + _lastRefreshDate = [NSDate date]; +} + #pragma mark - NSNotifications - (void)applicationDidFinishLaunching:(NSNotification *)notification { - [self lock]; + [self lockIfNeeded]; } - (void)applicationDidEnterBackground:(NSNotification *)notification { if (!self.backgroundLockVisible) { - [self lock]; + [self lockIfNeeded]; } } From a9753c7e5dea34b97d94e3baaf76c1adda57e6df Mon Sep 17 00:00:00 2001 From: david Date: Fri, 14 Oct 2016 08:51:19 +0200 Subject: [PATCH 2/3] Added seconds to lock variable --- VENTouchLock/VENTouchLock.h | 32 +++++++++++++++++++++++++++----- VENTouchLock/VENTouchLock.m | 22 +++++++++++++++++++++- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/VENTouchLock/VENTouchLock.h b/VENTouchLock/VENTouchLock.h index 9c853a8..73270f5 100644 --- a/VENTouchLock/VENTouchLock.h +++ b/VENTouchLock/VENTouchLock.h @@ -37,6 +37,22 @@ typedef NS_ENUM(NSUInteger, VENTouchLockTouchIDResponse) { passcodeAttemptLimit:(NSUInteger)attemptLimit splashViewControllerClass:(Class)splashViewControllerClass; +/** + Set the defaults. This method should be called at launch. + @param service The keychain service for which to set and return a passcode + @param account The keychain account for which to set and return a passcode + @param splashViewControllerClass The class of the custom splash view controller. This class should be a subclass of VENTouchLockSplashViewController and any of its custom initialization must be in its init function + @param reason The default message displayed on the TouchID prompt + @param secondsToLock The number of seconds from lastRefreshDate that the app will wait for lock + */ +- (void)setKeychainService:(NSString *)service + keychainAccount:(NSString *)account + touchIDReason:(NSString *)reason + secondsToLock:(NSUInteger)secondsToLock + passcodeAttemptLimit:(NSUInteger)attemptLimit + splashViewControllerClass:(Class)splashViewControllerClass; + + /** Returns YES if a passcode exists, and NO otherwise. */ @@ -93,6 +109,16 @@ typedef NS_ENUM(NSUInteger, VENTouchLockTouchIDResponse) { */ - (NSUInteger)passcodeAttemptLimit; +/** + Updates de refreshDate value with current date + */ +- (void) updateRefreshDate; + +/** + Sets the number of seconds that the app has to wait since lastRefreshDate to lock + */ +- (void) setSecondsToLock:(NSUInteger) secondsToLock; + /** If a passcode is set, calling this method will lock the app. Otherwise, calling it will not do anything. @note The app is automatically locked if needed (see method below) when on launch and on entering background. Use this method only if necessary in other circumstances. @@ -104,15 +130,11 @@ typedef NS_ENUM(NSUInteger, VENTouchLockTouchIDResponse) { */ - (void) lockIfNeeded; - /** @return The proxy for the receiver's user interface. Custom appearance preferences may optionally be set by editing the returned instance's properties. */ - (VENTouchLockAppearance *)appearance; -/** -Updates de refreshDate value with current date -*/ -- (void) updateRefreshDate; + @end diff --git a/VENTouchLock/VENTouchLock.m b/VENTouchLock/VENTouchLock.m index 0e33552..f971576 100644 --- a/VENTouchLock/VENTouchLock.m +++ b/VENTouchLock/VENTouchLock.m @@ -15,7 +15,7 @@ @interface VENTouchLock () @property (assign, nonatomic) Class splashViewControllerClass; @property (strong, nonatomic) UIView *snapshotView; @property (strong, nonatomic) VENTouchLockAppearance *appearance; -@property (nonatomic) NSInteger secondsToLock; +@property (nonatomic) NSUInteger secondsToLock; @property (strong, nonatomic) NSDate* lastRefreshDate; @end @@ -64,6 +64,22 @@ - (void)setKeychainService:(NSString *)service self.splashViewControllerClass = splashViewControllerClass; } +- (void)setKeychainService:(NSString *)service + keychainAccount:(NSString *)account + touchIDReason:(NSString *)reason + secondsToLock:(NSUInteger)secondsToLock + passcodeAttemptLimit:(NSUInteger)attemptLimit + splashViewControllerClass:(Class)splashViewControllerClass +{ + [self setKeychainService:service + keychainAccount:account + touchIDReason:reason + passcodeAttemptLimit:attemptLimit + splashViewControllerClass:splashViewControllerClass]; + + self.secondsToLock = secondsToLock; +} + #pragma mark - Keychain Methods @@ -235,6 +251,10 @@ - (void) updateRefreshDate { _lastRefreshDate = [NSDate date]; } +- (void) setSecondsToLock:(NSUInteger) secondsToLock { + _secondsToLock = secondsToLock; +} + #pragma mark - NSNotifications From 7e908ee4bbb94877acfe966de2cd8603db07299a Mon Sep 17 00:00:00 2001 From: david Date: Fri, 14 Oct 2016 09:04:03 +0200 Subject: [PATCH 3/3] Added lockIfNeeded in willEnterForeground --- VENTouchLock/VENTouchLock.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/VENTouchLock/VENTouchLock.m b/VENTouchLock/VENTouchLock.m index f971576..11202b7 100644 --- a/VENTouchLock/VENTouchLock.m +++ b/VENTouchLock/VENTouchLock.m @@ -276,7 +276,10 @@ - (void)applicationWillEnterForeground:(NSNotification *)notification [self.snapshotView removeFromSuperview]; self.snapshotView = nil; }); - + + if (!self.backgroundLockVisible) { + [self lockIfNeeded]; + } } @end