### Run Ruby Script for Token Swap Server Source: https://github.com/spotify/ios-sdk/blob/master/DemoProjects/SPTLoginSampleAppSwift/README.md Execute this command to start the local Ruby server for OAuth token swapping. Ensure all prerequisites are installed. ```sh $(rbenv which ruby) spotify_token_swap.rb ``` -------------------------------- ### Initialize SPTConfiguration Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Initialize SPTConfiguration with your client ID and redirect URI. Optionally set playURI to start playback during authorization. ```swift let configuration = SPTConfiguration( clientID: "your_client_id", redirectURL: URL(string: "your_redirect_uri")! ) // Optional: If you plan to connect SPTAppRemote you can start playback during authorization by setting playURI to a non-nil string. If Spotify is already playing it will continue playing even though a URI is provided. configuration.playURI = "" ``` -------------------------------- ### authorizeAndPlayURI Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemote.html Opens the Spotify app to obtain an access token and start playback. Returns YES if the Spotify app is installed and can attempt authorization, not if authorization succeeded. ```APIDOC ## authorizeAndPlayURI:asRadio:additionalScopes:sessionIdentifier:completionHandler: ### Description Open Spotify app to obtain access token and start playback. ### Method Signature - (void)authorizeAndPlayURI:(NSString *)_playURI_ asRadio:(BOOL)_asRadio_ additionalScopes:(nullable NSArray *)_additionalScopes_ sessionIdentifier:(nullable NSUUID *)_sessionIdentifier_ completionHandler:(void ( ^ __nullable ) ( BOOL success ))_completionHandler_ ### Parameters #### playURI - (NSString *) The URI to play. Use a blank string to attempt to play the user’s last song. #### asRadio - (BOOL) YES to start radio for the given URI. #### additionalScopes - (nullable NSArray) An array of scopes in addition to `app-remote-control`. Can be nil if you only need `app-remote-control`. #### sessionIdentifier - (nullable NSUUID *) An optional unique identifier for this specific session, which is used for analytics purposes. Every new attempt to connect to the Spotify app should have a new identifier, but the identifier used here should then be reused for the accompanied call to `connectWithSessionIdentifier:`. #### completionHandler - (void ( ^ __nullable ) ( BOOL success )) YES if the Spotify app is installed and an authorization attempt can be made, otherwise NO. Note: The return BOOL here is not a measure of whether or not authentication succeeded, only a check if the Spotify app is installed and can attempt to handle the authorization request. ### Declared In `SPTAppRemote.h` ``` -------------------------------- ### authorizeAndPlayURI:asRadio:completionHandler: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemote.html Opens the Spotify app to obtain an access token and start playback, with an option to initiate radio playback for the given URI. ```APIDOC ## authorizeAndPlayURI:asRadio:completionHandler: ### Description Open Spotify app to obtain access token and start playback. ### Method - (void)authorizeAndPlayURI:(NSString *)_playURI_ asRadio:(BOOL)_asRadio_ completionHandler:(void ( ^ __nullable ) ( BOOL success ))_completionHandler_ ### Parameters #### Path Parameters - **playURI** (NSString) - The URI to play. Use a blank string to attempt to play the user’s last song - **asRadio** (BOOL) - `YES` to start radio for the given URI. - **completionHandler** (BOOL) - `YES` if the Spotify app is installed and an authorization attempt can be made, otherwise `NO`. ### Note The return `BOOL` here is not a measure of whether or not authentication succeeded, only a check if the Spotify app is installed and can attempt to handle the authorization request. ``` -------------------------------- ### authorizeAndPlayURI:completionHandler: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemote.html Opens the Spotify app to obtain an access token and start playback. The provided URI will begin playing unless Spotify is already playing content. ```APIDOC ## authorizeAndPlayURI:completionHandler: ### Description Open Spotify app to obtain access token and start playback. The passed URI will start playing unless Spotify is already playing. ### Method - (void)authorizeAndPlayURI:(NSString *)_URI_ completionHandler:(void ( ^ __nullable ) ( BOOL success ))_completionHandler_ ### Parameters #### Path Parameters - **URI** (NSString) - The URI to play. Use a blank string to attempt to play the user’s last song - **completionHandler** (BOOL) - `YES` if the Spotify app is installed and an authorization attempt can be made, otherwise `NO`. ### Note The return `BOOL` here is not a measure of whether or not authentication succeeded, only a check if the Spotify app is installed and can attempt to handle the authorization request. ``` -------------------------------- ### authorizeAndPlayURI:asRadio:additionalScopes:completionHandler: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemote.html Opens the Spotify app to obtain an access token and start playback, allowing for additional scopes beyond the default 'app-remote-control'. ```APIDOC ## authorizeAndPlayURI:asRadio:additionalScopes:completionHandler: ### Description Open Spotify app to obtain access token and start playback. ### Method - (void)authorizeAndPlayURI:(NSString *)_playURI_ asRadio:(BOOL)_asRadio_ additionalScopes:(nullable NSArray *)_additionalScopes_ completionHandler:(void ( ^ __nullable ) ( BOOL success ))_completionHandler_ ### Parameters #### Path Parameters - **playURI** (NSString) - The URI to play. Use a blank string to attempt to play the user’s last song - **asRadio** (BOOL) - `YES` to start radio for the given URI. - **additionalScopes** (NSArray) - An array of scopes in addition to `app-remote-control`. Can be nil if you only need `app-remote-control` - **completionHandler** (BOOL) - `YES` if the Spotify app is installed and an authorization attempt can be made, otherwise `NO`. ### Note The return `BOOL` here is not a measure of whether or not authentication succeeded, only a check if the Spotify app is installed and can attempt to handle the authorization request. ``` -------------------------------- ### Initiate Session with Client-Only Authorization Option Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Forces authentication through the Spotify app only using SPTClientAuthorizationOption. Authorization fails if the Spotify app is not installed. ```swift sessionManager.initiateSession(with: scope, options: .clientOnly, campaign: nil) ``` -------------------------------- ### Authorize and Play URI Source: https://github.com/spotify/ios-sdk/blob/master/README.md Initiate the Spotify authentication flow and optionally play a specific track. Handles cases where the Spotify app is not installed. ```swift // Note: An empty string will play the user's last song or pick a random one. self.appRemote.authorizeAndPlayURI("spotify:track:69bp2EbF7Q2rqc5N3ylezZ") { spotifyInstalled in if !spotifyInstalled { /* * The Spotify app is not installed. * Use SKStoreProductViewController with SPTAppRemote.spotifyItunesItemIdentifier() to present the user * with a way to install the Spotify app. */ } } ``` -------------------------------- ### Initiate Session with Default Authorization Option Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Uses SPTDefaultAuthorizationOption for automatic detection of the best authentication method. Suitable when the Spotify app may or may not be installed. ```swift sessionManager.initiateSession(with: scope, options: .default, campaign: nil) ``` -------------------------------- ### play:asRadio:callback: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Asks the Spotify player to play the entity with the given identifier, optionally starting radio for that track. Implement SPTAppRemotePlayerStateDelegate for playback notifications. ```APIDOC ## play:asRadio:callback: ### Description Asks the Spotify player to play the entity with the given identifier. ### Method `- (void)play:(NSString *)_trackUri_ asRadio:(BOOL)_asRadio_ callback:(SPTAppRemoteCallback)_callback_` ### Parameters #### Path Parameters * **trackUri** (NSString) - The track URI to play. * **asRadio** (BOOL) - `YES` to start radio for track URI. * **callback** (SPTAppRemoteCallback) - On success `result` will be `YES`. On error `result` will be `nil` and `error` set. ### Discussion **Note:** Implement [`SPTAppRemotePlayerStateDelegate`](../Protocols/SPTAppRemotePlayerStateDelegate.html) and set yourself as [delegate](#//api/name/delegate) in order to be notified when the the track begins to play. ### Declared In `SPTAppRemotePlayerAPI.h` ``` -------------------------------- ### SPTAppRemotePlayerState Properties Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerState.html Access properties of the SPTAppRemotePlayerState protocol to get information about the current Spotify playback state. ```APIDOC ## SPTAppRemotePlayerState ### Description Represents the state within the Spotify player. ### Properties - **track** (id) - Required - The track being played in the Spotify player. - **playbackPosition** (NSInteger) - Required - The position of the playback in the Spotify player. - **playbackSpeed** (float) - Required - The speed of the playback in the Spotify player. - **paused** (BOOL) - Required - YES if the Spotify player is paused, otherwise NO. - **playbackRestrictions** (id) - Required - The playback restrictions currently in effect. - **playbackOptions** (id) - Required - The playback options currently in effect. - **contextTitle** (NSString *) - Required - The title of the currently playing context (e.g. the name of the playlist). - **contextURI** (NSURL *) - Required - The URI of the currently playing context (e.g. the URI of the playlist). ``` -------------------------------- ### + configurationWithClientID:redirectURL: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTConfiguration.html Convenience initializer for SPTConfiguration. A simpler way to create a new SPTConfiguration instance. ```APIDOC ## + configurationWithClientID:redirectURL: ### Description Convenience initializer for `SPTConfiguration` ### Method + (instancetype)configurationWithClientID:(NSString *)_clientID_ redirectURL:(NSURL *)_redirectURL_ ### Parameters * **clientID** (NSString) - Your client ID obtained from developer.spotify.com * **redirectURL** (NSURL) - Your redirect URL for Spotify to open your app again after authorization ### Return Value A newly initialized `SPTConfiguration` ``` -------------------------------- ### Initialize SPTConfiguration Source: https://github.com/spotify/ios-sdk/blob/master/README.md Initialize SPTConfiguration with your client ID and redirect URI. This is the first step in the authorization flow. ```swift let configuration = SPTConfiguration( clientID: "YOUR_CLIENT_ID", redirectURL: URL(string: "your_redirect_uri")! ) ``` -------------------------------- ### Connectivity API Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemote.html Provides access to the API used to get connectivity data from the Spotify app. This property is only populated when the App Remote is connected. ```APIDOC ## connectivityAPI ### Description The API used to get connectivity data from the Spotify app. ### Property `@property (nullable, nonatomic, strong, readonly) id connectivityAPI` ### Discussion **Note:** Will only be populated when the App Remote is connected. If you retain this object you must release it on disconnect. ### Declared In `SPTAppRemote.h` ``` -------------------------------- ### SPTAppRemoteCrossfadeState Properties Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemoteCrossfadeState.html This protocol exposes two properties: `enabled` to check the on/off state of crossfade, and `duration` to get the crossfade duration in milliseconds. ```APIDOC ## SPTAppRemoteCrossfadeState ### Description The `SPTAppRemoteCrossfadeState` represents the state of crossfade. ### Properties #### `enabled` The on/off state of crossfade. - **Type**: `BOOL` - **Readonly**: `YES` - **Getter**: `isEnabled` #### `duration` The duration of crossfade in milliseconds. The value is meaningless if crossfade is not enabled. - **Type**: `NSInteger` - **Readonly**: `YES` ### Declared In `SPTAppRemoteCrossfadeState.h` ``` -------------------------------- ### - initWithClientID:redirectURL: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTConfiguration.html Designated initializer for SPTConfiguration. Use this to create a new instance of SPTConfiguration with your client ID and redirect URL. ```APIDOC ## - initWithClientID:redirectURL: ### Description Designated initializer for `SPTConfiguration` ### Method - (instancetype)initWithClientID:(NSString *)_clientID_ redirectURL:(NSURL *)_redirectURL_ ### Parameters * **clientID** (NSString) - Your client ID obtained from developer.spotify.com * **redirectURL** (NSURL) - Your redirect URL for Spotify to open your app again after authorization ### Return Value A newly initialized `SPTConfiguration` ``` -------------------------------- ### Convenience Initializer Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemote.html Initializes a new SPTAppRemote instance with the provided configuration and log level. This is a convenience initializer that prepares the App Remote for connection. ```APIDOC ## initWithConfiguration:logLevel: ### Description Convenience Initializer for a new App Remote instance. ### Method - (instancetype)initWithConfiguration:(SPTConfiguration *)_configuration_ logLevel:(SPTAppRemoteLogLevel)_logLevel_ ### Parameters - **configuration** (SPTConfiguration) - The SPTConfiguration to use for client-id’s and redirect URLs - **logLevel** (SPTAppRemoteLogLevel) - The lowest severity to log to console. ### Return Value A fresh new App Remote, ready to connect. ### Declared In SPTAppRemote.h ``` -------------------------------- ### initWithConfiguration:delegate: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTSessionManager.html Initializes an SPTSessionManager instance with the provided configuration and delegate. ```APIDOC ## initWithConfiguration:delegate: ### Description Create an `SPTSessionManager` with the provided configuration. ### Method - (instancetype)initWithConfiguration:(SPTConfiguration *)_configuration_ delegate:(nullable id)_delegate_ ### Parameters #### Configuration - **configuration** (`SPTConfiguration` *) - Description: An [`SPTConfiguration`](../Classes/SPTConfiguration.html) object. #### Delegate - **delegate** (nullable id) - Description: An optional [delegate](#//api/name/delegate) conforming to [`SPTSessionManagerDelegate`](../Protocols/SPTSessionManagerDelegate.html). ### Return Value An `SPTSessionManager` with the desired configuration. ### Declared In `SPTSessionManager.h` ``` -------------------------------- ### playItem:skipToTrackIndex:callback: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Asks the Spotify player to play the provided content item starting at a specific track index. Implement SPTAppRemotePlayerStateDelegate for playback notifications. ```APIDOC ## playItem:skipToTrackIndex:callback: ### Description Asks the Spotify player to play the provided content item starting at the specified index. ### Method `- (void)playItem:(id)_contentItem_ skipToTrackIndex:(NSInteger)_index_ callback:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Path Parameters * **contentItem** (id) - The content item to play. * **index** (NSInteger) - The index of the track to skip to if applicable. * **callback** (SPTAppRemoteCallback) - On success `result` will be `YES`. On error `result` will be `nil` and error set. ### Discussion **Note:** Implement [`SPTAppRemotePlayerStateDelegate`](../Protocols/SPTAppRemotePlayerStateDelegate.html) and set yourself as [delegate](#//api/name/delegate) in order to be notified when the the track begins to play. **Note:** The `playable` property of the [`SPTAppRemoteContentItem`](../Protocols/SPTAppRemoteContentItem.html) indicates whether or not a content item is playable. **Note:** Sending an `index` parameter that is out of bounds is undefined. ### Declared In `SPTAppRemotePlayerAPI.h` ``` -------------------------------- ### connect Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemote.html Initiates a connection attempt to the Spotify application. If Spotify is not running, use authorizeAndPlayURI: to launch it. ```APIDOC ## connect ### Description Attempts to connect to the Spotify application. ### Method - (void)connect ### Discussion If the Spotify app is not running you will need to use authorizeAndPlayURI: to wake it up ### Declared In SPTAppRemote.h ``` -------------------------------- ### initiateSessionWithRawScope:options:campaign: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTSessionManager.html Initiates the Spotify authorization process using raw scope strings. This is an alternative to `initiateSessionWithScope:options:campaign:` for scopes not explicitly defined in `SPTScope`. ```APIDOC ## initiateSessionWithRawScope:options:campaign: ### Description Initiates the authorization process using raw scope strings. Prefer `initiateSessionWithScope:options:campaign` unless additional scopes are needed. ### Method `initiateSessionWithRawScope:options:campaign:` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **scope** (`NSString`) - The scope to request, e.g. "playlist-read-private user-read-email" if you wish to request read access to private playlists, and read access to the user’s email address. * **options** (`SPTAuthorizationOptions`) - Options bitmask that informs authorization behavior. * **campaign** (`NSString`*) - The campaign identifier, to help attribute where the account linking was initiated from. See `SPTSessionManagerDelegate` for messages regarding changes in session state. ``` -------------------------------- ### application:openURL:options: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTSessionManager.html Handles openURL callbacks from the AppDelegate to process access token URLs. ```APIDOC ## application:openURL:options: ### Description Handle openURL callbacks from the `AppDelegate` ### Method - (BOOL)application:(UIApplication *)_application_ openURL:(NSURL *)_URL_ options:(NSDictionary *)_options_ ### Parameters #### Application - **application** (`UIApplication` *) - Description: The `UIApplication` passed into the matching `AppDelegate` method #### URL - **URL** (`NSURL` *) - Description: The URL to attempt to parse the access token from #### Options - **options** (NSDictionary *) - Description: The options passed in to the matching `AppDelegate` method ### Return Value Returns `YES` if `SPTSessionManager` recognizes the URL and will attempt to parse an access token, otherwise returns `NO`. ### Declared In `SPTSessionManager.h` ``` -------------------------------- ### resume: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Asks the Spotify player to resume playback. On success, the result will be YES. On error, the result will be nil and an error will be set. ```APIDOC ## resume: ### Description Asks the Spotify player to resume playback. ### Method Objective-C method call ### Signature `- (void)resume:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Callback - `callback` (SPTAppRemoteCallback) - A callback block that receives the result of the operation. On success, `result` will be `YES`. On error, `result` will be `nil` and an error will be set. ``` -------------------------------- ### Initiate Session with Combined Authorization Options Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Combines multiple SPTAuthorizationOptions, such as .clientOnly and .spotifySchemeNotRegistered, for flexible authentication flows. ```swift let options: SPTAuthorizationOptions = [.clientOnly, .spotifySchemeNotRegistered] sessionManager.initiateSession(with: scope, options: options, campaign: nil) ``` -------------------------------- ### Import SpotifyiOS Framework Source: https://github.com/spotify/ios-sdk/blob/master/README.md Import the SpotifyiOS framework into your Swift source files to begin using the SDK's functionalities. ```swift import SpotifyiOS ``` -------------------------------- ### initiateSessionWithScope:options:campaign: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTSessionManager.html Initiates the Spotify authorization process with specified scopes, options, and campaign information. This method is used to request access to user data and functionalities. ```APIDOC ## initiateSessionWithScope:options:campaign: ### Description Initiates the authorization process to obtain a Spotify session. ### Method `initiateSessionWithScope:options:campaign:` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **scope** (`SPTScope`) - The scope to request, e.g. `SPTPlaylistReadPrivateScope`|`SPTUserReadEmailScope` if you wish to request read access to private playlists, and read access to the user’s email address. * **options** (`SPTAuthorizationOptions`) - Options bitmask that informs authorization behavior. * **campaign** (`NSString`*) - The campaign identifier, to help attribute where the account linking was initiated from. See `SPTSessionManagerDelegate` for messages regarding changes in session state. ``` -------------------------------- ### Handle Custom URL Schemes in Legacy AppDelegate Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Use the application:openURL:options: method in the legacy AppDelegate pattern for custom URL schemes. ```swift func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { // Use this method if your SpotifyRedirectURL is a custom URL scheme (myapp://callback) return sessionManager.application(application, open: url, options: options) } ``` -------------------------------- ### fetchContentItemForURI:callback: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemoteContentAPI.html Fetches the content item for the provided URI. A Spotify URI is provided as a string. ```APIDOC ## fetchContentItemForURI:callback: ### Description Fetches the content item for the provided URI. ### Method `- (void)fetchContentItemForURI:(NSString *)_URI_ callback:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Parameters - **URI** (NSString *) - A Spotify URI as string - **callback** (nullable SPTAppRemoteCallback) - The callback to be called once the request is completed. ``` -------------------------------- ### Initialize SPTSessionManager Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Initialize SPTSessionManager with your configuration and delegate. ```swift self.sessionManager = SPTSessionManager(configuration: configuration, delegate: self) ``` -------------------------------- ### Initiate Spotify Authorization Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Initiate the authorization process by calling sessionManager.initiateSession with the desired scopes and options. Scopes define the data your application can access. ```swift /* Scopes let you specify exactly what types of data your application wants to access, and the set of scopes you pass in your call determines what access permissions the user is asked to grant. For more information, see https://developer.spotify.com/web-api/using-scopes/. */ let scope: SPTScope = [.userFollowRead, .appRemoteControl] sessionManager.initiateSession(with: scope, options: .default, campaign: nil) ``` -------------------------------- ### seekToPosition:callback: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Asks the Spotify player to seek to the specified position in milliseconds. On success, the result will be YES. On error, the result will be nil and an error will be set. ```APIDOC ## seekToPosition:callback: ### Description Asks the Spotify player to seek to the specified position. ### Method Objective-C method call ### Signature `- (void)seekToPosition:(NSInteger)_position_ callback:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Position - `position` (NSInteger) - The position to seek to in milliseconds. #### Callback - `callback` (SPTAppRemoteCallback) - A callback block that receives the result of the operation. On success, `result` will be `YES`. On error, `result` will be `nil` and an error will be set. ``` -------------------------------- ### SPTAppRemotePlaybackOptionsRepeatModeContext Constant Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Constants/SPTAppRemotePlaybackOptionsRepeatMode.html Represents the state where the current context (e.g., album, playlist) will repeat. ```objc SPTAppRemotePlaybackOptionsRepeatModeContext ``` -------------------------------- ### Configure Info.plist for Spotify Scheme Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Add the spotify scheme to your app's Info.plist to allow Spotify to be queried. ```xml LSApplicationQueriesSchemes spotify ``` -------------------------------- ### fetchCapabilitiesWithCallback: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemoteUserAPI.html Fetches the current users capabilities from the Spotify app. The callback block will be invoked when the fetch request has completed. On success, the result will be an instance of SPTAppRemoteUserCapabilities. On error, the result will be nil and an error will be set. ```APIDOC ## fetchCapabilitiesWithCallback: ### Description Fetches the current users capabilities from the Spotify app. ### Method `- (void)fetchCapabilitiesWithCallback:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Callback - `callback` (SPTAppRemoteCallback) - A callback block that will be invoked when the fetch request has completed. On success `result` will be an instance of `id`SPTAppRemoteUserCapabilities. On error `result` will be `nil` and `error` will be set. ### Declared In `SPTAppRemoteUserAPI.h` ``` -------------------------------- ### canSkipPrevious Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlaybackRestrictions.html YES if the user can skip to the previous track, otherwise NO. ```APIDOC ## canSkipPrevious ### Description YES if the user can skip to the previous track, otherwise NO. ### Property `@property (nonatomic, readonly) BOOL canSkipPrevious` ``` -------------------------------- ### canSkipNext Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlaybackRestrictions.html YES if the user can skip to the next track, otherwise NO. ```APIDOC ## canSkipNext ### Description YES if the user can skip to the next track, otherwise NO. ### Property `@property (nonatomic, readonly) BOOL canSkipNext` ``` -------------------------------- ### canRepeatContext Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlaybackRestrictions.html YES if the user can repeat the current context, otherwise NO. ```APIDOC ## canRepeatContext ### Description YES if the user can repeat the current context, otherwise NO. ### Property `@property (nonatomic, readonly) BOOL canRepeatContext` ``` -------------------------------- ### fetchLibraryStateForURI:callback: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemoteUserAPI.html Fetches the current users library state for a given album or track URI. The callback block will be invoked when the fetch request has completed. On success, the result will be an instance of SPTAppRemoteLibraryState. On error, the result will be nil and an error will be set. ```APIDOC ## fetchLibraryStateForURI:callback: ### Description Fetches the current users library state for a given album or track uri. ### Method `- (void)fetchLibraryStateForURI:(NSString *)_URI_ callback:(SPTAppRemoteCallback)_callback_` ### Parameters #### Path Parameters - **URI** (NSString) - The URI of the album or track we are fetching the state for #### Callback - `callback` (SPTAppRemoteCallback) - A callback block that will be invoked when the fetch request has completed. On success `result` will be an instance of `id`SPTAppRemoteLibraryState. On error `result` will be `nil` and `error` will be set. ### Declared In `SPTAppRemoteUserAPI.h` ``` -------------------------------- ### SPTAppRemoteConnectionParams Initialization Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemoteConnectionParams.html Initializes a new set of connection parameters with the provided access token, default image size, and image format. ```APIDOC ## initWithAccessToken:defaultImageSize:imageFormat: ### Description Initialize a set of new connection parameters. ### Method - (instancetype)initWithAccessToken:(nullable NSString *)_accessToken_ defaultImageSize:(struct CGSize)_defaultImageSize_ imageFormat:(SPTAppRemoteConnectionParamsImageFormat)_imageFormat_ ### Parameters - **accessToken** (NSString *) - The access token obtained after authentication. - **defaultImageSize** (struct CGSize) - The desired size of received images. (0,0) acts as a wildcard and accepts any size. - **imageFormat** (SPTAppRemoteConnectionParamsImageFormat) - The desired image format of received images. ### Return Value A set of connection parameters ready to be used when initiating a connection to the Spotify app. ### Discussion This is the designated initializer. ``` -------------------------------- ### Handle Universal Links in SceneDelegate Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Implement the scene:continueUserActivity: method in your SceneDelegate to handle Universal Links. ```swift func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { if userActivity.activityType == NSUserActivityTypeBrowsingWeb { sessionManager.application(UIApplication.shared, continue: userActivity, restorationHandler: nil) } } ``` -------------------------------- ### Establish SPTAppRemote Connection Source: https://github.com/spotify/ios-sdk/blob/master/README.md Set the delegate for SPTAppRemote and attempt to establish a connection. Handle connection success and failure callbacks. ```swift self.appRemote.delegate = self self.appRemote.connect() ``` ```swift // MARK: AppRemoteDelegate func appRemoteDidEstablishConnection(_ appRemote: SPTAppRemote) { // Connection was successful, you can begin issuing commands } func appRemote(_ appRemote: SPTAppRemote, didFailConnectionAttemptWithError error: Error?) { // Connection failed } func appRemote(_ appRemote: SPTAppRemote, didDisconnectWithError error: Error?) { // Connection disconnected } ``` -------------------------------- ### sessionManager:didInitiateSession: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTSessionManagerDelegate.html This message is sent when a session has been initiated successfully. Implement this method to handle successful session initiation. ```APIDOC ## sessionManager:didInitiateSession: ### Description This message is sent when a session has been initiated successfully. ### Method Objective-C ### Parameters #### Parameters - **manager** (`SPTSessionManager` *) - The SPTSessionManager that initiated the session. - **session** (`SPTSession` *) - The initiated SPTSession object. ``` -------------------------------- ### Configure Token Swap and Refresh URLs Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Set your token swap and refresh URLs if you plan to implement the token swap URL method. These endpoints handle client secrets and communicate with Spotify's servers. ```swift // Set these URLs to your backend which contains the secret to exchange for an access token configuration.tokenSwapURL = URL(string: "http://[your_server]/swap") configuration.tokenRefreshURL = URL(string: "http://[your_server]/refresh") ``` -------------------------------- ### Handle Universal Links in Legacy AppDelegate Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Use the application:continueUserActivity:restorationHandler: method in the legacy AppDelegate pattern for Universal Links. ```swift func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { // Use this method if your SpotifyRedirectURL is a universal link (https://myapp.com/callback) return sessionManager.application(application, continue: userActivity, restorationHandler: restorationHandler) } ``` -------------------------------- ### application:continueUserActivity:restorationHandler: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTSessionManager.html Handles continueUserActivity callbacks from the AppDelegate for user activity restoration. ```APIDOC ## application:continueUserActivity:restorationHandler: ### Description Handle continueUserActivity callbacks from the `AppDelegate` ### Method - (BOOL)application:(UIApplication *)_application_ continueUserActivity:(NSUserActivity *)_userActivity_ restorationHandler:(void ( ^ ) (NSArray > *__nullable restorableObjects ))_restorationHandler_ ### Parameters #### Application - **application** (`UIApplication` *) - Description: The `UIApplication` passed into the matching `AppDelegate` method #### User Activity - **userActivity** (`NSUserActivity` *) - Description: An object encapsulating a user activity supported by this responder. #### Restoration Handler - **restorationHandler** (void ( ^ ) (NSArray > *__nullable restorableObjects )) - Description: A block to execute if your app creates objects to perform the task the user was performing ### Return Value Returns `YES` if `SPTSessionManager` recognizes the URL and will attempt to parse an access token, otherwise returns `NO`. ### Declared In `SPTSessionManager.h` ``` -------------------------------- ### SPTAppRemotePlaybackOptionsRepeatModeTrack Constant Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Constants/SPTAppRemotePlaybackOptionsRepeatMode.html Represents the state where the current track will repeat. ```objc SPTAppRemotePlaybackOptionsRepeatModeTrack ``` -------------------------------- ### getAvailablePodcastPlaybackSpeeds Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Asks the Spotify player for available podcast playback speeds. ```APIDOC ## getAvailablePodcastPlaybackSpeeds ### Description Asks the Spotify player for available podcast playback speeds. ### Method Objective-C ### Endpoint N/A ### Parameters #### Callback On success `result` will be an `NSArray` of [`SPTAppRemotePodcastPlaybackSpeed`](../Protocols/SPTAppRemotePodcastPlaybackSpeed.html) objects. On error `result` will be `nil` and `error` set. ### Declared In `SPTAppRemotePlayerAPI.h` ``` -------------------------------- ### skipToNext: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Asks the Spotify player to skip to the next track. On success, the result will be YES. On error, the result will be nil and an error will be set. ```APIDOC ## skipToNext: ### Description Asks the Spotify player to skip to the next track. ### Method Objective-C method call ### Signature `- (void)skipToNext:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Callback - `callback` (SPTAppRemoteCallback) - A callback block that receives the result of the operation. On success, `result` will be `YES`. On error, `result` will be `nil` and an error will be set. ``` -------------------------------- ### appRemoteVersion Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemote.html Retrieves the current version of the Spotify App Remote SDK. ```APIDOC ## appRemoteVersion ### Description Determine the current version of the Spotify App Remote. ### Method + (NSString *)appRemoteVersion ### Return Value The current version of the Spotify App Remote. ### Declared In SPTAppRemote.h ``` -------------------------------- ### skipToPrevious: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Asks the Spotify player to skip to the previous track. On success, the result will be YES. On error, the result will be nil and an error will be set. ```APIDOC ## skipToPrevious: ### Description Asks the Spotify player to skip to the previous track. ### Method Objective-C method call ### Signature `- (void)skipToPrevious:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Callback - `callback` (SPTAppRemoteCallback) - A callback block that receives the result of the operation. On success, `result` will be `YES`. On error, `result` will be `nil` and an error will be set. ``` -------------------------------- ### Implement SPTSessionManagerDelegate Methods Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Implement the SPTSessionManagerDelegate methods to handle authorization responses, including failures, renewals, and successful initiations. ```swift // MARK: - SPTSessionManagerDelegate func sessionManager(manager: SPTSessionManager, didFailWith error: Error) { // Authorization Failed } func sessionManager(manager: SPTSessionManager, didRenew session: SPTSession) { // Session Renewed } func sessionManager(manager: SPTSessionManager, didInitiate session: SPTSession) { // Authorization Succeeded } ``` -------------------------------- ### appRemote:didFailConnectionAttemptWithError: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemoteDelegate.html Called when the connection attempt made by the App Remote failed. ```APIDOC ## appRemote:didFailConnectionAttemptWithError: ### Description Called when the connection attempt made by the App Remote failed. ### Method - (void)appRemote:(SPTAppRemote *)appRemote didFailConnectionAttemptWithError:(nullable NSError *)error ### Parameters #### appRemote - **appRemote** (SPTAppRemote *) - The App Remote that failed to connect. #### error - **error** (nullable NSError *) - The error that occurred. ### Declared In SPTAppRemote.h ``` -------------------------------- ### Initialize SPTAppRemote Source: https://github.com/spotify/ios-sdk/blob/master/README.md Initialize SPTAppRemote with the configured SPTConfiguration. This object is used for all interactions with the Spotify app. ```swift self.appRemote = SPTAppRemote(configuration: configuration, logLevel: .debug) ``` -------------------------------- ### enqueueTrackUri Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Adds a track to the user’s currently playing queue. ```APIDOC ## enqueueTrackUri:callback: ### Description Adds a track to the user’s currently playing queue. ### Method Objective-C ### Endpoint N/A ### Parameters #### trackUri The track URI to add to the queue. #### Callback On success `result` will be `YES`. On error `result` will be `nil` and error set. ### Declared In `SPTAppRemotePlayerAPI.h` ``` -------------------------------- ### Initiate Session with Spotify Scheme Not Registered Option Source: https://github.com/spotify/ios-sdk/blob/master/docs/auth.md Uses SPTSpotifySchemeNotRegisteredAuthorizationOption to bypass the canOpenURL check and attempt to open the Spotify app directly. This option is useful when the 50 URL scheme limit is reached and does not require adding the Spotify URL scheme to LSApplicationQueriesSchemes. ```swift sessionManager.initiateSession(with: scope, options: .spotifySchemeNotRegistered, campaign: nil) ``` -------------------------------- ### fetchImageForItem:withSize:callback: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemoteImageAPI.html Fetches an image with the given ID from the Spotify app. The callback receives a UIImage on success or nil with an error on failure. ```APIDOC ## fetchImageForItem:withSize:callback: ### Description Fetch an image with the given ID from the Spotify app. ### Method `- (void)fetchImageForItem:(id)_imageRepresentable_ withSize:(CGSize)_imageSize_ callback:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Parameters - **imageRepresentable** (id) - The item containing the ID of the image to fetch. - **imageSize** (CGSize) - The size of the image to fetch. - **callback** (nullable SPTAppRemoteCallback) - On success `result` will be an instance of `UIImage` On error `result` will be nil and error set ``` -------------------------------- ### pause: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Asks the Spotify player to pause playback. On success, the result will be YES. On error, the result will be nil and an error will be set. ```APIDOC ## pause: ### Description Asks the Spotify player to pause playback. ### Method Objective-C method call ### Signature `- (void)pause:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Callback - `callback` (SPTAppRemoteCallback) - A callback block that receives the result of the operation. On success, `result` will be `YES`. On error, `result` will be `nil` and an error will be set. ``` -------------------------------- ### Handle Universal Link Redirect Source: https://github.com/spotify/ios-sdk/blob/master/README.md Implement this method in your SceneDelegate to parse the access token from a Universal Link redirect after authorization. ```swift func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { if userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL { let parameters = appRemote.authorizationParameters(from: url) if let access_token = parameters?[SPTAppRemoteAccessTokenKey] { appRemote.connectionParameters.accessToken = access_token self.accessToken = access_token } else if let error_description = parameters?[SPTAppRemoteErrorDescriptionKey] { // Handle authorization error print("Authorization error: \(error_description)") } } } ``` -------------------------------- ### subscribeToCapabilityChanges: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemoteUserAPI.html Subscribes to capability changes from the Spotify app. The callback block will be invoked when the subscription request has completed. On success, the result will be YES. On error, the result will be nil and an error will be set. To receive notifications, implement SPTAppRemoteUserAPIDelegate and set yourself as the delegate. ```APIDOC ## subscribeToCapabilityChanges: ### Description Subscribes to capability changes from the Spotify app. ### Method `- (void)subscribeToCapabilityChanges:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Callback - `callback` (SPTAppRemoteCallback) - A callback block that will be invoked when the subscription request has completed. On success `result` will `YES`. On error `result` will be `nil` and `error` will be set. ### Discussion **Note:** Implement [`SPTAppRemoteUserAPIDelegate`](../Protocols/SPTAppRemoteUserAPIDelegate.html) and set yourself as [`delegate`](#//api/name/delegate) in order to be notified when the the capabilities changes. ### Declared In `SPTAppRemoteUserAPI.h` ``` -------------------------------- ### fetchRootContentItemsForType:callback: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemoteContentAPI.html Fetches the root level of content items for the current user. The content returned is based on the users' home feeds and may vary. If the user is offline, this method will return the user’s offline content, if any. Deprecated: Use fetchRecommendedContentItemsForType:flattenContainers:callback: instead. ```APIDOC ## fetchRootContentItemsForType:callback: ### Description Fetches the root level of content items for the current user. ### Method `-(void)fetchRootContentItemsForType:(SPTAppRemoteContentType)_contentType_ callback:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Parameters - **contentType** (SPTAppRemoteContentType) - A type that is used to retrieve content for a specific use-case. - **callback** (nullable SPTAppRemoteCallback) - The callback to be called once the request is completed. ### Discussion **Note:** The content returned is based on the users' home feeds, and as such may vary between different users. If the user has no network connection or Spotify is forced offline, this method will return the user’s offline content, if any. **Deprecated.** Use [fetchRecommendedContentItemsForType:flattenContainers:callback:](#//api/name/fetchRecommendedContentItemsForType:flattenContainers:callback:) instead. ``` -------------------------------- ### SPTConfiguration Properties Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTConfiguration.html This section details the properties of the SPTConfiguration class, which store your application's Spotify credentials and configuration settings. ```APIDOC ## SPTConfiguration Properties ### Overview A configuration class, holding the credentials provided for your app on the Spotify Developer website. ### Properties * **clientID** (NSString) - Your app’s Client ID from developer.spotify.com * **redirectURL** (NSURL) - Your redirect URL. This is how the Spotify app will open your application after user authorization. * **companyName** (NSString, nullable) - Name of the company * **tokenSwapURL** (NSURL, nullable) - The URL to use for attempting to swap an authorization code for an access token. You should only set this if your clientID has a clientSecret and you have a backend service that holds the secret and can exchange the code and secret for an access token. * **tokenRefreshURL** (NSURL, nullable) - The URL to use for attempting to renew an access token with a refresh token. You should only set this if your clientID has a clientSecret and you have a backend service that holds the secret and can use a refresh token to get a new access token. * **playURI** (NSString, nullable) - If requesting the SPTAppRemoteControlScope you can provide an optional uri to begin playing after a successful authentication. To continue the user’s last session set this to a blank string @“”. If this value is nil or SPTAppRemoteControlScope is not requested no audio will play. If Spotify is already playing it will continue playing even though a URI is provided. ``` -------------------------------- ### setShuffle:callback: Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Asks the Spotify player to set shuffle mode. On success, the result will be YES. On error, the result will be nil and an error will be set. ```APIDOC ## setShuffle:callback: ### Description Asks the Spotify player to set shuffle mode. ### Method Objective-C method call ### Signature `- (void)setShuffle:(BOOL)_shuffle_ callback:(nullable SPTAppRemoteCallback)_callback_` ### Parameters #### Shuffle - `shuffle` (BOOL) - `YES` to enable shuffle, `NO` to disable. #### Callback - `callback` (SPTAppRemoteCallback) - A callback block that receives the result of the operation. On success, `result` will be `YES`. On error, `result` will be `nil` and an error will be set. ``` -------------------------------- ### subscribeToPlayerState Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Protocols/SPTAppRemotePlayerAPI.html Subscribes to player state changes from the Spotify app. Implement SPTAppRemotePlayerStateDelegate and set yourself as delegate to be notified. ```APIDOC ## subscribeToPlayerState ### Description Subscribes to player state changes from the Spotify app. ### Method Objective-C ### Endpoint N/A ### Parameters #### Callback On success `result` will be an instance of `id`SPTAppRemotePlayerState. On error `result` will be nil and error set. ### Discussion **Note:** Implement [`SPTAppRemotePlayerStateDelegate`](../Protocols/SPTAppRemotePlayerStateDelegate.html) and set yourself as [delegate](#//api/name/delegate) in order to be notified when the the player state changes. ### Declared In `SPTAppRemotePlayerAPI.h` ``` -------------------------------- ### delegate Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemote.html Set a delegate object to receive connection status changes and other events from the App Remote. ```APIDOC ## delegate ### Description The delegate to notify for connection status changes and other events originating from the App Remote. ### Property @property (nonatomic, weak) id delegate ### Declared In SPTAppRemote.h ``` -------------------------------- ### authorizationParametersFromURL Source: https://github.com/spotify/ios-sdk/blob/master/docs/html/Classes/SPTAppRemote.html Parses an access token or error description from a URL passed to application:openURL:options:. ```APIDOC ## authorizationParametersFromURL: ### Description Parse out an access token or error description from a url passed to application:openURL:options: ### Method Signature - (nullable NSDictionary *)authorizationParametersFromURL:(NSURL *)_url_ ### Parameters #### url - (NSURL *) The URL returned from the Spotify app after calling authorizeAndPlayURI. ### Return Value A dictionary containing the access token or error description from the provided URL. Will return nil if the URL Scheme does not match the redirect URI provided. Use `SPTAppRemoteAccessTokenKey` and `SPTAppRemoteErrorDescriptionKey` to get the appropriate values. ### Declared In `SPTAppRemote.h` ```