-
Notifications
You must be signed in to change notification settings - Fork 409
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
Adding a second UIWindow to display the UIAlertController. #18
Conversation
…ts rootViewController
if UIApplication.sharedApplication().updaterWindow == nil { | ||
let window = UIWindow(frame: UIScreen.mainScreen().bounds) | ||
window.rootViewController = UIViewController() | ||
window.windowLevel = UIWindowLevelAlert + 1 // make the window appear above all other view controllers and windows |
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.
This relies on undocumented behavior - I suggest we stick with UIWindowLevelAlert
.
I'll look at this in detail over the next few days and confer with @getaaron before accepting the PR. |
*/ | ||
if UIApplication.sharedApplication().updaterWindow == nil { | ||
let window = UIWindow(frame: UIScreen.mainScreen().bounds) | ||
window.rootViewController = UIViewController() |
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 see that this fixes the rotation issue I thought would exist. Clever! Have you tested this code on iOS 7? Does it still work as expected?
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'm fairly certain that it will work on iOS 7, but I'll test and confirm.
@dbettermann This looks excellent. I haven't tested it on iOS 7, but if it works there, it's certainly an improvement over what we have now. I left some minor suggestions, mostly stylistic. Thanks for the PR. |
@getaaron @ArtSabintsev Thank you for considering it. I'll make some changes based on the feedback later today. |
Made some changes that align with the feedback. Check it out! |
Hah, this is pretty clever from the looks of it. Will DL and accept the PR tonight if everything works. Great job! |
Looks excellent. Accepting the PR and pushing a commit over it to give you credit! Great job my man! Now, I need to make these changes in the ObjC repo... =p I'll give you credit there once I get to it. |
Adding a second UIWindow to display the UIAlertController.
Problem:
With UIAlertView we could call
show()
from the AppDelegate and have the UIAlertView implementation find the visible view controller and add the view as a subview. This no longer works with the new iOS 8 UIAlertController because it's a subclass of UIViewController (instead of UIView) and has to be presented just like any other view controller. CallingpresentViewController(...)
on the UIWindow'srootViewController
will not work if therootViewController
is not visible when the app becomes active. We need a way to display the UIAlertController without calculating (or passing a reference to) the visible view controller.Solution:
By using a second UIWindow we can ensure that its rootViewController is always the visible view controller. If we set the
windowLevel
of the second UIWindow to beUIWindowLevelAlert + 1
we ensure that the window will always appear above any other views and view controllers in the app. Lastly, we need to create a strong reference to the second window via an associated object. If we do not do this, the window will be released before it's displayed.