Inherits from SPTPartialTrack : SPTJSONObjectBase : NSObject
Conforms to SPTJSONObject
Declared in SPTTrack.h

Overview

This class represents a track on the Spotify service.

API Docs: https://developer.spotify.com/web-api/track-endpoints/

API Console: https://developer.spotify.com/web-api/console/tracks/

API Model: https://developer.spotify.com/web-api/object-model/#track-object-full

Properties

externalIds

Any external IDs of the track, such as the ISRC code.

@property (nonatomic, readonly, copy) NSDictionary *externalIds

Declared In

SPTTrack.h

popularity

The popularity of the track as a value between 0.0 (least popular) to 100.0 (most popular).

@property (nonatomic, readonly) double popularity

Declared In

SPTTrack.h

Class Methods

createRequestForTrack:withAccessToken:market:error:

Create a request for fetching one track.

+ (NSURLRequest *)createRequestForTrack:(NSURL *)uri withAccessToken:(NSString *)accessToken market:(NSString *)market error:(NSError **)error

Parameters

uri

The Spotify URI of the track to request.

accessToken

An access token.

market

Either a ISO 3166-1 country code to filter the results to, or from_token to pick the market from the session (requires the user-read-private scope), or nil for no market filtering.

error

An optional pointer to an NSError that will receive the error code if operation failed.

Discussion

Parse the response into an SPTListPage using SPTTrack trackFromData:withResponse:error:

See https://developer.spotify.com/web-api/get-list-new-releases/ for more information on parameters

Declared In

SPTTrack.h

createRequestForTracks:withAccessToken:market:error:

Create a request for fetching multiple rtacks

+ (NSURLRequest *)createRequestForTracks:(NSArray *)uris withAccessToken:(NSString *)accessToken market:(NSString *)market error:(NSError **)error

Parameters

uris

An array of Spotify Track URIs.

accessToken

An access token.

market

Either a ISO 3166-1 country code to filter the results to, or from_token to pick the market from the session (requires the user-read-private scope), or nil for no market filtering.

error

An optional pointer to an NSError that will receive the error code if operation failed.

Discussion

Parse the response into an NSArray of SPTTrack-objects using SPTTrack trackFromDecodedJSON:

See https://developer.spotify.com/web-api/get-list-new-releases/ for more information on parameters

Declared In

SPTTrack.h

identifierFromURI:

Returns the identifier for a Spotify Track uri.

+ (NSString *)identifierFromURI:(NSURL *)uri

Parameters

uri

An track uri.

Return Value

The track id, or nil if an invalid track uri was passed.

Discussion

Note: This method takes Spotify URIs in the form spotify:*, NOT HTTP URLs.

Declared In

SPTTrack.h

identifiersFromArray:

Returns a list of track id’s from an array containing either SPTPartialTrack, SPTTrack or NSURL’s

+ (NSArray *)identifiersFromArray:(NSArray *)tracks

Parameters

tracks

An array of tracks.

Return Value

An array of track id’s.

Declared In

SPTTrack.h

isTrackURI:

Checks if the Spotify URI is a valid Spotify Track URI.

+ (BOOL)isTrackURI:(NSURL *)uri

Parameters

uri

The Spotify URI to check.

Discussion

Note: This method takes Spotify URIs in the form spotify:*, NOT HTTP URLs.

Declared In

SPTTrack.h

trackFromData:withResponse:error:

Parse an JSON object structure into an array of SPTTrack object.

+ (instancetype)trackFromData:(NSData *)data withResponse:(NSURLResponse *)response error:(NSError **)error

Parameters

data

The API response data

response

The API response object

error

An optional NSError that will be set if an error occured when parsing the data.

Return Value

an SPTTrack object, or nil if the parsing failed.

Declared In

SPTTrack.h

trackFromDecodedJSON:error:

Parse an JSON object structure into an array of SPTTrack object.

+ (instancetype)trackFromDecodedJSON:(id)decodedObject error:(NSError **)error

Parameters

decodedObject

The decoded JSON structure to parse.

error

An optional NSError that will be set if an error occured when parsing the data.

Return Value

an SPTAlbum object, or nil if the parsing failed.

Declared In

SPTTrack.h

trackWithURI:accessToken:market:callback:

Request the track at the given Spotify URI.

+ (void)trackWithURI:(NSURL *)uri accessToken:(NSString *)accessToken market:(NSString *)market callback:(SPTRequestCallback)block

Parameters

uri

The Spotify URI of the track to request.

accessToken

An access token.

market

Either a ISO 3166-1 country code to filter the results to, or from_token to pick the market from the session (requires the user-read-private scope), or nil for no market filtering.

block

The block to be called when the operation is complete. The block will pass a Spotify SDK metadata object on success, otherwise an error.

Discussion

This is a convenience method on top of the SPTTrack createRequestForTracks:withAccessToken:error: and SPTRequest performRequest:callback: methods

See: https://developer.spotify.com/web-api/get-track/

Note: This method takes Spotify URIs in the form spotify:*, NOT HTTP URLs.

Declared In

SPTTrack.h

tracksFromData:withResponse:error:

Parse an JSON object structure into an array of SPTTrack object.

+ (NSArray *)tracksFromData:(NSData *)data withResponse:(NSURLResponse *)response error:(NSError **)error

Parameters

data

The API response data

response

The API response object

error

An optional NSError that will be set if an error occured when parsing the data.

Return Value

an array of SPTTrack objects, or nil if the parsing failed.

Declared In

SPTTrack.h

tracksFromDecodedJSON:error:

Parse an JSON object structure into an array of SPTTrack objects.

+ (NSArray *)tracksFromDecodedJSON:(id)decodedObject error:(NSError **)error

Parameters

decodedObject

The decoded JSON structure to parse.

error

An optional NSError that will be set if an error occured when parsing the data.

Return Value

an SPTAlbum object, or nil if the parsing failed.

Declared In

SPTTrack.h

tracksWithURIs:accessToken:market:callback:

Request multiple tracks with given an array of Spotify URIs.

+ (void)tracksWithURIs:(NSArray *)uris accessToken:(NSString *)accessToken market:(NSString *)market callback:(SPTRequestCallback)block

Parameters

uris

An array of Spotify Track URIs.

accessToken

An access token.

market

Either a ISO 3166-1 country code to filter the results to, or from_token to pick the market from the session (requires the user-read-private scope), or nil for no market filtering.

block

The block to be called when the operation is complete. The block will pass an array of Spotify SDK metadata objects on success, otherwise an error.

Discussion

This is a convenience method on top of the SPTTrack createRequestForTracks:withAccessToken:error: and SPTRequest performRequest:callback: methods

See: https://developer.spotify.com/web-api/get-several-tracks/

Note: This method takes an array of Spotify URIs in the form spotify:*, NOT HTTP URLs.

Declared In

SPTTrack.h

uriStringsFromArray:

Returns a list of track uri’s as NSString’s from an array containing either SPTPartialTrack, SPTTrack or NSURL’s

+ (NSArray *)uriStringsFromArray:(NSArray *)tracks

Parameters

tracks

An array of tracks.

Return Value

An array of track uri strings.

Declared In

SPTTrack.h

urisFromArray:

Returns a list of track uri’s as NSURL’s from an array containing either SPTPartialTrack, SPTTrack or NSURL’s

+ (NSArray *)urisFromArray:(NSArray *)tracks

Parameters

tracks

An array of tracks.

Return Value

An array of track uri’s.

Declared In

SPTTrack.h