diff --git a/VENTouchLock/VENTouchLock.h b/VENTouchLock/VENTouchLock.h index 642ee90..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,15 +109,32 @@ 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 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 + + +@end diff --git a/VENTouchLock/VENTouchLock.m b/VENTouchLock/VENTouchLock.m index a6272e8..11202b7 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) NSUInteger secondsToLock; +@property (strong, nonatomic) NSDate* lastRefreshDate; @end @@ -62,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 @@ -217,18 +235,38 @@ - (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]; +} + +- (void) setSecondsToLock:(NSUInteger) secondsToLock { + _secondsToLock = secondsToLock; +} + #pragma mark - NSNotifications - (void)applicationDidFinishLaunching:(NSNotification *)notification { - [self lock]; + [self lockIfNeeded]; } - (void)applicationDidEnterBackground:(NSNotification *)notification { if (!self.backgroundLockVisible) { - [self lock]; + [self lockIfNeeded]; } } @@ -238,7 +276,10 @@ - (void)applicationWillEnterForeground:(NSNotification *)notification [self.snapshotView removeFromSuperview]; self.snapshotView = nil; }); - + + if (!self.backgroundLockVisible) { + [self lockIfNeeded]; + } } @end