Skip to content

Instantly share code, notes, and snippets.

@surayashivji
Created January 30, 2017 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save surayashivji/6dda4138d41b30f561618e1bb5c718a0 to your computer and use it in GitHub Desktop.
Save surayashivji/6dda4138d41b30f561618e1bb5c718a0 to your computer and use it in GitHub Desktop.
setting root view controller in app delegate
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