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.
iOS 11
- Install the latest version of Spotify from the App Store onto the device you will be using for development. Run the Spotify app and log in 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.
- Add
SpotifyLogin.xcframeworkto your project by dragging and dropping it in Frameworks, 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.
- Declare the Spotify’s URL scheme
spotifyby adding theLSApplicationQueriesSchemeskey.
Swift
import SpotifyLogin
let configuration = Configuration(clientID: "your_client_id", redirectURLString: "your_redirect_uri")Objective-C
#import <SpotifyLogin/SpotifyLogin.h>
SPTConfiguration* configuration = [[SPTConfiguration alloc] initWithClientID:@"your_client_id" redirectURLString:@"your_redirect_uri"];2. Initialise SessionManager with your configuration and set an object that conforms SessionManagerDelegate to the delegate of the instance.
Swift
let sessionManager = SessionManager(configuration: configuration)
sessionManager.delegate = <#delegate object#>Objective-C
_sessionManager = [[SPTSessionManager alloc] initWithConfiguration:configuration];
_sessionManager.delegate = <#delegate object#>;3. Implement application(_:open:options:) method to your UIApplicationDelegate and call sessionManager's application(_:open:options:) there.
Swift
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return sessionManager.openURL(url)
}
}Objective-C
@implementation AppDelegate
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return [_sessionManager openURL:url];
}
@endSwift
sessionManager.startAuthorizationCodeProcess(with: [.playlistModifyPublic, .playlistModifyPrivate])Objective-C
[_sessionManager startAuthorizationCodeProcessWith:SPTScopePlaylistModifyPublic|SPTScopePlaylistModifyPublic campaign:NULL];