SPTAppRemote Class Reference

Inherits from NSObject
Declared in SPTAppRemote.h

Overview

The SPTAppRemote is the main entry point for interacting with the Spotify app using the Spotify App Remote for iOS.

– initWithConfiguration:logLevel:

Convenience Initializer for a new App Remote instance

- (instancetype)initWithConfiguration:(SPTConfiguration *)configuration logLevel:(SPTAppRemoteLogLevel)logLevel

Parameters

configuration

The SPTConfiguration to use for client-id’s and redirect URLs

logLevel

The lowest severity to log to console.

Return Value

A fresh new App Remote, ready to connect.

Declared In

SPTAppRemote.h

– initWithConfiguration:connectionParameters:logLevel:

Designated Initializer for a new App Remote instance

- (instancetype)initWithConfiguration:(SPTConfiguration *)configuration connectionParameters:(SPTAppRemoteConnectionParams *)connectionParameters logLevel:(SPTAppRemoteLogLevel)logLevel

Parameters

configuration

The SPTConfiguration to use for client-id’s and redirect URLs

connectionParameters

SPTAppRemoteConnectionParams for custom image sizes and types, and to hold the accessToken

logLevel

The lowest severity to log to console.

Return Value

A fresh new App Remote, ready to connect.

Declared In

SPTAppRemote.h

+ checkIfSpotifyAppIsActive:

Checks if the Spotify app is active on the user’s device. You can use this to determine if maybe you should prompt the user to connect to Spotify (because you know they are already using Spotify if it is active). The Spotify app will be considered active if music is playing or the app is active in the background.

+ (void)checkIfSpotifyAppIsActive:(void ( ^ ) ( BOOL active ))completion

Parameters

completion

Completion block for determining the result of the check. YES if Spotify is active, othewise NO.

Declared In

SPTAppRemote.h

+ appRemoteVersion

Determine the current version of the Spotify App Remote

+ (NSString *)appRemoteVersion

Return Value

The current version of the Spotify App Remote

Declared In

SPTAppRemote.h

+ spotifyItunesItemIdentifier

The Spotify app iTunes item identifier for use with SKStoreProductViewController for installing Spotify from the App Store.

+ (NSNumber *)spotifyItunesItemIdentifier

Return Value

An NSNumber representing the Spotify iTunes item identifier to be used for the SKStoreProductParameterITunesItemIdentifier key

Declared In

SPTAppRemote.h

  connectionParameters

The parameters to use during connection.

@property (nonatomic, strong, readonly) SPTAppRemoteConnectionParams *connectionParameters

Declared In

SPTAppRemote.h

  connected

YES if the App Remote is connected to the Spotify application, otherwise NO.

@property (nonatomic, assign, readonly, getter=isConnected) BOOL connected

Discussion

Note: Not KVO’able.

See The SPTAppRemoteDelegate in order to receive updates when the connection status changes.

Declared In

SPTAppRemote.h

  delegate

The delegate to notify for connection status changes and other events originating from the App Remote.

@property (nonatomic, weak) id<SPTAppRemoteDelegate> delegate

Declared In

SPTAppRemote.h

– connect

Attempts to connect to the Spotify application.

- (void)connect

Discussion

If the Spotify app is not running you will need to use authorizeAndPlayURI: to wake it up

Declared In

SPTAppRemote.h

– connectWithSessionIdentifier:

Attempts to connect to the Spotify application with a given session identifier.

- (void)connectWithSessionIdentifier:(NSUUID *)sessionIdentifier

Parameters

sessionIdentifier

The unique session identifier which was used when calling authorizeAndPlayURI:asRadio:additionalScopes:sessionIdentifier:

Discussion

If the Spotify app is not running you will need to use authorizeAndPlayURI: to wake it up.

If authorizeAndPlayURI was used without a given session identifier, connect should be used instead of this method.

Declared In

SPTAppRemote.h

– disconnect

Disconnect from the Spotify application

- (void)disconnect

Declared In

SPTAppRemote.h

– authorizeAndPlayURI:

Open Spotify app to obtain access token and start playback. The passed URI will start playing unless Spotify is already playing.

- (BOOL)authorizeAndPlayURI:(NSString *)URI

Parameters

URI

The URI to play. Use a blank string to attempt to play the user’s last song

Return Value

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:

Open Spotify app to obtain access token and start playback.

- (BOOL)authorizeAndPlayURI:(NSString *)playURI asRadio:(BOOL)asRadio

Parameters

playURI

The URI to play. Use a blank string to attempt to play the user’s last song

asRadio

YES to start radio for the given URI.

Return Value

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:additionalScopes:

Open Spotify app to obtain access token and start playback.

- (BOOL)authorizeAndPlayURI:(NSString *)playURI asRadio:(BOOL)asRadio additionalScopes:(nullable NSArray<NSString*> *)additionalScopes

Parameters

playURI

The URI to play. Use a blank string to attempt to play the user’s last song

asRadio

YES to start radio for the given URI.

additionalScopes

An array of scopes in addition to app-remote-control. Can be nil if you only need app-remote-control

Return Value

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:additionalScopes:sessionIdentifier:

Open Spotify app to obtain access token and start playback.

- (BOOL)authorizeAndPlayURI:(NSString *)playURI asRadio:(BOOL)asRadio additionalScopes:(nullable NSArray<NSString*> *)additionalScopes sessionIdentifier:(nullable NSUUID *)sessionIdentifier

Parameters

playURI

The URI to play. Use a blank string to attempt to play the user’s last song

asRadio

YES to start radio for the given URI.

additionalScopes

An array of scopes in addition to app-remote-control. Can be nil if you only need app-remote-control

sessionIdentifier

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:.

Return Value

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

– authorizationParametersFromURL:

Parse out an access token or error description from a url passed to application:openURL:options:

- (nullable NSDictionary<NSString*,NSString*> *)authorizationParametersFromURL:(NSURL *)url

Parameters

url

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

  playerAPI

The API used to control the Spotify player.

@property (nullable, nonatomic, strong, readonly) id<SPTAppRemotePlayerAPI> playerAPI

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

  imageAPI

The API used to fetch images from the Spotify app.

@property (nullable, nonatomic, strong, readonly) id<SPTAppRemoteImageAPI> imageAPI

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

  userAPI

The API used to fetch user data from the Spotify app.

@property (nullable, nonatomic, strong, readonly) id<SPTAppRemoteUserAPI> userAPI

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

  contentAPI

The API used to fetch content from the Spotify app.

@property (nullable, nonatomic, strong, readonly) id<SPTAppRemoteContentAPI> contentAPI

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

  connectivityAPI

The API used to get connectivity data from the Spotify app.

@property (nullable, nonatomic, strong, readonly) id<SPTAppRemoteConnectivityAPI> 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