Skip to content

Instantly share code, notes, and snippets.

@surayashivji
Created January 30, 2017 10:16
Show Gist options
  • Select an option

  • Save surayashivji/6dda4138d41b30f561618e1bb5c718a0 to your computer and use it in GitHub Desktop.

Select an option

Save surayashivji/6dda4138d41b30f561618e1bb5c718a0 to your computer and use it in GitHub Desktop.

Revisions

  1. surayashivji created this gist Jan 30, 2017.
    41 changes: 41 additions & 0 deletions AppDelegate.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    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)
    }
    }