skagedal
skagedal

Reputation: 2411

Using the Spotify iOS SDK, how can I tell what market the user is connected to?

Is it possible to tell the country associated with the current user's account with the iOS Spotify SDK? How? I have not been able to find anything in the docs.

(I'd like to get the ISO 3166-1 alpha-2 country code so that another (unauthenticated) user can do searches with the web api and only find tracks that we will ultimately be able to play using the authenticated user that is using the SDK.)

Upvotes: 0

Views: 256

Answers (1)

skagedal
skagedal

Reputation: 2411

Found it. It is available from the territory field of the SPTUser object. Here is how you might get it after having logged in and received a session object, example code in Swift:

SPTUser.requestCurrentUserWithAccessToken(session.accessToken) { error, object in        
    guard let user = object as? SPTUser,
              territory = user.territory else {
        print("Could not get territory, error: \(error)"
        return
    }
    print(territory)
}

However, you will get nil values for the territory unless you have included SPTAuthUserReadPrivateScope in requestedScopes when setting up your SPTAuth object.

Upvotes: 0

Related Questions