Skip to content

Instantly share code, notes, and snippets.

@marmelroy
Created August 31, 2017 14:39
Show Gist options
  • Save marmelroy/b8f0b65d4275e0e8f89d1ec5f1ed2403 to your computer and use it in GitHub Desktop.
Save marmelroy/b8f0b65d4275e0e8f89d1ec5f1ed2403 to your computer and use it in GitHub Desktop.
SpotifyLoginSample.swift
// Set up your app's URL Types and URL schemes.
// Add the following to your AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
SpotifyLogin.shared.configure(clientID: <#T##String#>, clientSecret: <#T##String#>, redirectURL: <#T##URL#>)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = SpotifyLogin.shared.applicationOpenURL(url) { (error) in }
return handled
}
// Add a log in button
let button = SpotifyLoginButton(viewController: self, scopes: [.streaming, .userLibraryRead])
self.view.addSubview(button)
// Retrieve the access token
SpotifyLogin.shared.getAccessToken { (accessToken, error) in
if error != nil {
// User is not logged in, show log in flow.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment