Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions VENTouchLock/VENTouchLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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


@end
47 changes: 44 additions & 3 deletions VENTouchLock/VENTouchLock.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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];
}
}

Expand All @@ -238,7 +276,10 @@ - (void)applicationWillEnterForeground:(NSNotification *)notification
[self.snapshotView removeFromSuperview];
self.snapshotView = nil;
});


if (!self.backgroundLockVisible) {
[self lockIfNeeded];
}
}

@end