Skip to content

Commit

Permalink
Set AutoLock with timer
Browse files Browse the repository at this point in the history
Unfortunately the method to use Protected Data hooks didn't work because
if you send the app to the background, then it won't receive the private
data status change.
  • Loading branch information
Carlos Cabanero committed Jul 5, 2017
1 parent 8b21522 commit d97f880
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Settings/Base.lproj/Settings.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<sections>
<tableViewSection footerTitle="Lock Blink after the device awakes from sleep. Request Passcode or TouchID to unlock Blink." id="9Vo-jE-Sfm">
<tableViewSection footerTitle="Lock Blink after 10 minutes in the background. Request Passcode or TouchID to unlock Blink." id="9Vo-jE-Sfm">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" rowHeight="44" id="qGk-FE-K2U">
<rect key="frame" x="0.0" y="35" width="375" height="44"/>
Expand Down
15 changes: 12 additions & 3 deletions Settings/Security/BKTouchIDAuthManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

@import LocalAuthentication;

#define MAX_INTERVAL_INACTIVE 10 * 60

static BKTouchIDAuthManager *sharedManager = nil;
static BOOL authRequired = NO;

Expand All @@ -45,7 +47,9 @@ @interface BKTouchIDAuthManager ()

@end

@implementation BKTouchIDAuthManager
@implementation BKTouchIDAuthManager {
NSTimeInterval inactiveTimeStamp;
}

+ (id)sharedManager
{
Expand All @@ -72,7 +76,7 @@ - (instancetype)init
- (void)registerforDeviceLockNotif
{
//Screen lock notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displayStatusChanged:) name:UIApplicationProtectedDataWillBecomeUnavailable object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displayStatusChanged:) name:UIApplicationDidEnterBackgroundNotification object:nil];
// CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
// NULL, // observer
// displayStatusChanged, // callback
Expand All @@ -93,6 +97,10 @@ - (void)registerforDeviceLockNotif

- (void)didBecomeActive:(NSNotification *)notification
{
if (authRequired == NO && inactiveTimeStamp != 0) {
authRequired = ([[NSDate date] timeIntervalSince1970] - inactiveTimeStamp) > MAX_INTERVAL_INACTIVE;
}
inactiveTimeStamp = 0;
if ([BKTouchIDAuthManager requiresTouchAuth]) {
[self authenticateUser];
}
Expand All @@ -103,7 +111,8 @@ - (void)didBecomeActive:(NSNotification *)notification
- (void) displayStatusChanged:(NSNotification *)notification
{
// the "com.apple.springboard.lockcomplete" notification will always come after the "com.apple.springboard.lockstate" notification
authRequired = YES;
inactiveTimeStamp = [[NSDate date] timeIntervalSince1970];
//authRequired = YES;
}

+ (BOOL)requiresTouchAuth
Expand Down

0 comments on commit d97f880

Please sign in to comment.