SpotifyLogin
Overview
SpotifyLogin is a lightweight framework that enables your application to obtain the authentication code from the Spotify app. Please note that this framework is currently under development and only supports a subset of the ios-sdk's functionalities. If you wish to use all features related to authentication, please utilize ios-sdk.
Minimum Requirement
iOS 11
Usage
Prepare Your Environment
- Install the latest version of Spotify from the App Store onto the device you will be using for development. Run the Spotify app and login or sign up.
- Register Your Application. You will need to register your application at My Applications and obtain a client ID. When you register your app you will also need to allowlist a redirect URI that the Spotify app will use to callback to your app after authorization.
Installation
- Add
SpotifyLogin.xcframeworkto your project by dragging and dropping it in Framworks, Libraries, and Embedded Content - In your info.plist add the following changes:
- Add your redirect URI you registered at My Applications. You will need to add your redirect URI under "URL types" and "URL Schemes". Be sure to set a unique "URL identifier" as well. More info on URL Schemes
- Declare the Spotify’s URL scheme
spotifyby adding theLSApplicationQueriesSchemeskey.
Get authentication code
- Initialise
Configurationwith your client ID and redirect URI.
import SpotifyLogin
let configuration = Configuration(clientID: "your_client_id", redirectURLString: "your_redirect_uri")- Initialise
SessionManagerwith your configuration and set an object that conformsSessionManagerDelegateto thedelegateof the instance.
let sessionManager = SessionManager(configuration: configuration)
sessionManager.delegate = <#delegate object#>- Implement
application(_:open:options:)method to yourUIApplicationDelegateand call sessionManager'sapplication(_:open:options:)there.
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return sessionManager.application(application, open: url, options: options)
}
}- Start the authrization process with the scopes you need.
sessionManager.startAuthorizationCodeProcess(with: [.playlistModifyPublic, .playlistModifyPrivate])