Use window instead of pushing the lock onto the view controller#65
Use window instead of pushing the lock onto the view controller#65ayanonagon wants to merge 9 commits intodaz/support_carthage_watchosfrom
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 |
| else { | ||
| displayController = splashViewController; | ||
| self.displayController = splashViewController; | ||
| } |
There was a problem hiding this comment.
What do you think about adding:
self.lockWindow.windowLevel = UIWindowLevelAlert; // or UIWindowLevelAlert + 1?
There was a problem hiding this comment.
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.
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.
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'swindowLevelto be equal to thewindowLevelof the currently key window. - Make our lock window a
UIWindowsubclass 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
UIWindowDidBecomeKeyNotificationandUIWindowDidBecomeVisibleNotificationnotifications. 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 ofVENTouchLockand that this is undefined behavior.
There was a problem hiding this comment.
@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.
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.