Name: SpotifyLogin
Owner: Spotify
Description: Swift framework for authenticating with the Spotify API
Created: 2017-08-04 14:07:41.0
Updated: 2018-05-22 18:16:04.0
Pushed: 2018-02-04 20:09:48.0
Size: 141
Language: Swift
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
SpotifyLogin is a Swift 4 Framework for authenticating with the Spotify API.
Usage of this framework is bound under the Developer Terms of Use.
SpotifyLogin is appropriate for prototyping and non-commercial use only.
If your app is meant for commercial production usage, SpotifyLogin can NOT be used.
SpotifyLogin requires Xcode 9.0+. It is compatible with iOS 9 or later.
You will need to register your app in the Developer Portal.
Make sure to use a unique redirect url and to supply the bundle ID from your app.
After registering, you will receive a client ID and a client secret.
Set up SpotifyLogin using any of the methods detailed below (Cocoapods / Carthage / manually).
In Xcode, go to your app's target and select the Info tab. At the bottom, of the screen you will find URL Types, expand the list and create a new one.
Add the app's identifer as the Identifier and the redirect url scheme in URL schemes.
Additionally, you will need to add “spotify-action” to the LSApplicationQueriesSchemes key:
Add the following to your app delegate:
application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
SpotifyLogin.shared.configure(clientID: <#T##String#>, clientSecret: <#T##String#>, redirectURL: <#T##URL#>)
return true
application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = SpotifyLogin.shared.applicationOpenURL(url) { (error) in }
return handled
You can retrieve an access token and check if a user is logged in by:
ifyLogin.shared.getAccessToken { (accessToken, error) in
if error != nil {
// User is not logged in, show log in flow.
}
This also automatically takes care of renewing expired tokens.
To add the default log in button:
button = SpotifyLoginButton(viewController: self, scopes: [.streaming, .userLibraryRead])
.view.addSubview(button)
The scopes define the set of permissions your app will be able to use. For more information about available scopes, see Scopes Documentation
To log out:
ifyLogin.shared.logout()
The log in flow is completed in applicationOpenURL. To respond to a successful log in, you can add your own code in the completion handler or respond to the SpotifyLoginSuccessful notification:
ficationCenter.default.addObserver(self, selector: #selector(loginSuccessful), name: .SpotifyLoginSuccessful, object: nil)
Access the current user's username:
username = SpotifyLogin.shared.username
To trigger the log in flow from a custom action:
ifyLoginPresenter.login(from: self, scopes: [.streaming, .userLibraryRead])
ce 'https://github.com/CocoaPods/Specs.git'
'SpotifyLogin', '~> 0.1'
Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with Homebrew using the following command:
ew update
ew install carthage
To integrate SpotifyLogin into your Xcode project using Carthage, specify it in your Cartfile
:
ub "spotify/SpotifyLogin"
This project adheres to the Open Code of Conduct. By contributing, you are expected to honor this code.