Skip to content

Instantly share code, notes, and snippets.

@tempire
Created August 25, 2015 01:52
Show Gist options
  • Save tempire/e6f1a2831f5688d352da to your computer and use it in GitHub Desktop.
Save tempire/e6f1a2831f5688d352da to your computer and use it in GitHub Desktop.
present view controller on entering background
func frontViewController(window: UIWindow) -> UIViewController {
if let rootVC = window.rootViewController {
var frontVC = rootVC
while (true) {
if let vc = frontVC.presentedViewController { frontVC = vc }
else { break }
}
return frontVC
}
return window.rootViewController!
}
func applicationDidEnterBackground(application: UIApplication) {
if let window = application.windows[0] as? UIWindow,
let model = self.model,
let vc = storyboard.instantiateViewControllerWithIdentifier("LoginWithStoredAuthVC") as? LoginWithStoredAuthVC {
window.rootViewController?.view.endEditing(true)
let frontVC = self.frontViewController(window)
if frontVC is LoginWithStoredAuthVC || frontVC is LoginWithUserAndPassVC { return }
vc.model = model
vc.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
vc.modalPresentationStyle = UIModalPresentationStyle.FullScreen
frontVC.presentViewController(vc, animated: false, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment