Skip to content

Instantly share code, notes, and snippets.

@SylarRuby
Created January 12, 2017 08:00
Show Gist options
  • Save SylarRuby/49070aef94dfe4fb31515e15b026d711 to your computer and use it in GitHub Desktop.
Save SylarRuby/49070aef94dfe4fb31515e15b026d711 to your computer and use it in GitHub Desktop.
Redirects user to loginVC if not currently logged in
/**
* If any issues, be sure to import Firebase or FirebaseAuth and check your Podfile
*
*/
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let root = UIApplication.shared.keyWindow?.rootViewController
let lc: LoginVC = storyboard.instantiateViewController(withIdentifier: "loginVC") as! LoginVC
// If the user is not logged in, redirect to loginViewController (loginVC)
if (FIRAuth.auth()?.currentUser) != nil {
// Do stuff if shortcutItem.type == "your shortcut"
} else {
// Passing the shortcutItem to the loginVC's variable
lc.params = "\(shortcutItem.type)"
root?.present(lc, animated: false, completion: { () -> Void in
completionHandler(true)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment