-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use window instead of pushing the lock onto the view controller #65
base: daz/support_carthage_watchos
Are you sure you want to change the base?
Changes from all commits
4ca404b
2101e4f
9ffea95
20ce671
f6befe3
787ed31
6ef390d
9bcc7e0
e235c84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,13 @@ @interface VENTouchLock () | |
@property (copy, nonatomic) NSString *touchIDReason; | ||
@property (assign, nonatomic) NSUInteger passcodeAttemptLimit; | ||
@property (assign, nonatomic) Class splashViewControllerClass; | ||
@property (strong, nonatomic) UIView *snapshotView; | ||
@property (strong, nonatomic) VENTouchLockAppearance *appearance; | ||
|
||
@property (strong, nonatomic) UIViewController *displayController; | ||
|
||
@property (weak, nonatomic) UIWindow *mainWindow; | ||
@property (strong, nonatomic) UIWindow *lockWindow; | ||
|
||
@end | ||
|
||
@implementation VENTouchLock | ||
|
@@ -41,9 +45,11 @@ - (instancetype)init | |
self = [super init]; | ||
if (self) { | ||
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; | ||
[notificationCenter addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil]; | ||
[notificationCenter addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; | ||
[notificationCenter addObserver:self selector:@selector(applicationDidFinishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil]; | ||
|
||
[notificationCenter addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; | ||
[notificationCenter addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil]; | ||
|
||
self.mainWindow = [[UIApplication sharedApplication].windows firstObject]; | ||
} | ||
return self; | ||
} | ||
|
@@ -62,6 +68,11 @@ - (void)setKeychainService:(NSString *)service | |
self.splashViewControllerClass = splashViewControllerClass; | ||
} | ||
|
||
- (BOOL)isPasscodePresented | ||
{ | ||
return self.lockWindow.isKeyWindow; | ||
} | ||
|
||
|
||
#pragma mark - Keychain Methods | ||
|
||
|
@@ -91,6 +102,8 @@ - (void)setPasscode:(NSString *)passcode | |
|
||
- (void)deletePasscode | ||
{ | ||
[self unlockAnimated:NO]; | ||
|
||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:VENTouchLockUserDefaultsKeyTouchIDActivated]; | ||
[VENTouchLockEnterPasscodeViewController resetPasscodeAttemptHistory]; | ||
[[NSUserDefaults standardUserDefaults] synchronize]; | ||
|
@@ -174,71 +187,60 @@ - (void)requestTouchIDWithCompletion:(void (^)(VENTouchLockTouchIDResponse))comp | |
|
||
- (void)lock | ||
{ | ||
if (![self isPasscodeSet]) { | ||
if (![self isPasscodeSet] || self.isPasscodePresented) { | ||
return; | ||
} | ||
|
||
if (self.splashViewControllerClass != NULL) { | ||
VENTouchLockSplashViewController *splashViewController = [[self.splashViewControllerClass alloc] init]; | ||
if ([splashViewController isKindOfClass:[VENTouchLockSplashViewController class]]) { | ||
UIWindow *mainWindow = [[UIApplication sharedApplication].windows firstObject]; | ||
UIViewController *rootViewController = [UIViewController ventouchlock_topMostController]; | ||
UIViewController *displayController; | ||
self.lockWindow = [[UIWindow alloc] initWithFrame:self.mainWindow.frame]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about adding: self.lockWindow.windowLevel = UIWindowLevelAlert; // or UIWindowLevelAlert + 1 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will give us the benefit of overlaying other windows which reside at lower, more normal levels. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Up the By introducing a delay helps, but not ideal
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation for
To address your concerns, @zinthemoney, I propose doing a few things to guard against becoming obscured and to alert developers to the possibility that their app may be doing something that collides with how VENTouchLock operates.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hyperspacemark I agree with your points, my only concern on having this |
||
self.lockWindow.windowLevel = UIWindowLevelAlert + 1; | ||
|
||
if (self.appearance.splashShouldEmbedInNavigationController) { | ||
displayController = [splashViewController ventouchlock_embeddedInNavigationControllerWithNavigationBarClass:self.appearance.navigationBarClass]; | ||
self.displayController = [splashViewController ventouchlock_embeddedInNavigationControllerWithNavigationBarClass:self.appearance.navigationBarClass]; | ||
} | ||
else { | ||
displayController = splashViewController; | ||
self.displayController = splashViewController; | ||
} | ||
|
||
BOOL fromBackground = [UIApplication sharedApplication].applicationState == UIApplicationStateBackground; | ||
if (fromBackground) { | ||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; | ||
VENTouchLockSplashViewController *snapshotSplashViewController = [[self.splashViewControllerClass alloc] init]; | ||
[snapshotSplashViewController setIsSnapshotViewController:YES]; | ||
UIViewController *snapshotDisplayController; | ||
if (self.appearance.splashShouldEmbedInNavigationController) { | ||
snapshotDisplayController = [snapshotSplashViewController ventouchlock_embeddedInNavigationControllerWithNavigationBarClass:self.appearance.navigationBarClass]; | ||
} | ||
else { | ||
snapshotDisplayController = snapshotSplashViewController; | ||
} | ||
[snapshotDisplayController loadView]; | ||
[snapshotDisplayController viewDidLoad]; | ||
snapshotDisplayController.view.frame = mainWindow.bounds; | ||
self.snapshotView = snapshotDisplayController.view; | ||
[mainWindow addSubview:self.snapshotView]; | ||
} | ||
self.lockWindow.rootViewController = self.displayController; | ||
|
||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
self.backgroundLockVisible = YES; | ||
[rootViewController presentViewController:displayController animated:NO completion:nil]; | ||
[self.lockWindow makeKeyAndVisible]; | ||
}); | ||
} | ||
} | ||
} | ||
|
||
- (void)unlockAnimated:(BOOL)animated | ||
{ | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
if (animated) { | ||
[UIView animateWithDuration:0.2 animations:^{ | ||
self.lockWindow.alpha = 0; | ||
} completion:^(BOOL finished) { | ||
self.lockWindow.hidden = YES; | ||
[self.mainWindow makeKeyAndVisible]; | ||
}]; | ||
} else { | ||
self.lockWindow.hidden = YES; | ||
[self.mainWindow makeKeyAndVisible]; | ||
} | ||
}); | ||
} | ||
|
||
|
||
#pragma mark - NSNotifications | ||
|
||
- (void)applicationDidFinishLaunching:(NSNotification *)notification | ||
- (void)applicationDidBecomeActive:(NSNotification *)notification | ||
{ | ||
[self lock]; | ||
} | ||
|
||
- (void)applicationDidEnterBackground:(NSNotification *)notification | ||
{ | ||
if (!self.backgroundLockVisible) { | ||
[self lock]; | ||
} | ||
} | ||
|
||
- (void)applicationWillEnterForeground:(NSNotification *)notification | ||
- (void)applicationWillResignActive:(NSNotification *)notification | ||
{ | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
[self.snapshotView removeFromSuperview]; | ||
self.snapshotView = nil; | ||
}); | ||
|
||
[self lock]; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
PODS: | ||
- KIF (3.2.2): | ||
- KIF/XCTest (= 3.2.2) | ||
- KIF/XCTest (3.2.2) | ||
- KIF (3.3.0): | ||
- KIF/Core (= 3.3.0) | ||
- KIF/Core (3.3.0) | ||
- SSKeychain (1.2.2) | ||
|
||
DEPENDENCIES: | ||
- KIF (~> 3.0) | ||
- SSKeychain (~> 1.2.2) | ||
|
||
SPEC CHECKSUMS: | ||
KIF: b0bd762b0c7890b04920cf618021d6d4fd5127bd | ||
KIF: 0a82046d06f3648799cac522d2d0f7934214caac | ||
SSKeychain: 88767e903ee8d274ed380e364d96b7a101235286 | ||
|
||
COCOAPODS: 0.37.2 | ||
COCOAPODS: 0.38.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we be sure this is the application's main window? It might be better to directly ask
UIApplication
'sdelegate
for its window?