Created
January 30, 2017 10:16
-
-
Save surayashivji/6dda4138d41b30f561618e1bb5c718a0 to your computer and use it in GitHub Desktop.
setting root view controller in app delegate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppDelegate: UIResponder, UIApplicationDelegate, SpotifyAuthDelegate { | |
var window: UIWindow? | |
var navigationController: UINavigationController = UINavigationController() | |
private var auth: SpotifyAuth { | |
return SpotifyAuth.shared | |
} | |
private var rootViewController: UIViewController { | |
return SpotifyAuth.shared.isAuthenticated ? YesViewController() : ViewController() | |
} | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
auth.delegate = self | |
self.window = UIWindow(frame: UIScreen.main.bounds) | |
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) | |
navigationController = storyboard.instantiateInitialViewController() as! UINavigationController | |
navigationController.viewControllers = [rootViewController] | |
self.window?.rootViewController = navigationController | |
self.window?.makeKeyAndVisible() | |
return true | |
} | |
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { | |
auth.handle(authenticationURL: url) | |
auth.fetchAccessToken() | |
return true | |
} | |
// MARK: - SpotifyAuthDelegate | |
func sessionUpdated(in spotifyAuth: SpotifyAuth) { | |
navigationController.setViewControllers([rootViewController], animated: false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment