-
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?
Conversation
hierarchy This is cleaner and also lets us show the lock when app switching too so the user can hide sensitive information behind the lock when in the app switch viewer.
Hm... Looks like Travis isn't too happy about Xcode 6.3... Any idea why we ended up with a box with 6.3 instead of 6.4? |
Code looks good though! @zinthemoney you wanna take a look at this change too, for a second set of 👀? I know you mentioned at DubDub this year that you're using this in Chime, so I just wanted to make sure these changes don't break too much for y'all! |
@ayanonagon, can you give a little background / problems on start using the @eliperkins, by replacing |
@zinthemoney Sure! Two main reasons:
Let me know if you have any more questions. Thanks for trying it out :D |
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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Up the UIWindowLevel
doesn't help in the situation i mentioned, by the same token that UIApplication
is a shared instance. Basically, we want to make sure that we call [self.lockWindow makeKeyAndVisible];
last with respect to whatever the host app might be doing. Hope this makes sense :)
By introducing a delay helps, but not ideal
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.lockWindow makeKeyAndVisible];
});
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.
The documentation for -makeKeyAndVisible
says that the method makes sure the window is displayed above all other windows with the same window level or lower.
This is a convenience method to make the receiver the main window and displays it in front of other windows at the same window level or lower.
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.
- On the invocation of
-lock
, check if-[UIApplication windows]
has more than 1 window and-[UIApplication keyWindow]
is not equal to-[id<UIApplicationDelegate> window]
. If this is the case, we should setlockWindow
'swindowLevel
to be equal to thewindowLevel
of the currently key window. - Make our lock window a
UIWindow
subclass that overrides-setRootViewController:
and raises an assertion if the argument is any type of view controller that we don't expect. This won't crash in release builds but will crash in debug builds. - Observe the
UIWindowDidBecomeKeyNotification
andUIWindowDidBecomeVisibleNotification
notifications. If we're currently locked and we receive these messages, raise an assertion that informs the developer that they've attempted to display a window on top ofVENTouchLock
and that this is undefined behavior.
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.
@hyperspacemark I agree with your points, my only concern on having this obscured behavior
that (potentially) breaks existing VENTouchLock
integrations is adding integration complexity. We should solve the issue within the framework, and not pass on the responsibility to the developers. @ayanonagon, @eliperkins what do you think?
@zinthemoney ah, certainly true. The idea spurned out of some information from this blog post: http://www.thecave.com/2015/09/28/how-to-present-an-alert-view-using-uialertcontroller-when-you-dont-have-a-view-controller/, specifically:
I think setting the window level might help us mitigate some of those concerns: https://github.com/venmo/VENTouchLock/pull/65/files#r40910236 by at least placing our window over the rest. I'll have to check to see if this accomplishes what you're discussing, however, that touching our application's window will definitely have some interesting side-effects. |
might not necessarily hide the window if the other window’s level is lower
[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]; |
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
's delegate
for its window?
@ayanonagon what's the status of this PR? |
What's the status on this PR? |
Not to speak for everyone, but as an active maintainer we haven’t been focused on implementing this. If you’d like to chat with me or test or suggest things we’d love to hear it. But as it stands this implementation doesn’t function for everyone. |
No description provided.