react-native-spotify-remote icon indicating copy to clipboard operation
react-native-spotify-remote copied to clipboard

Error: Spotify does not appear to be installed. Note: You must whitelist the 'spotify' URL scheme in your info.plist

Open P-Russell opened this issue 4 years ago • 14 comments
trafficstars

Hi there.

I would like my persist spotify sessions over closing and opening the app that we are building.

To achieve this I am experimenting with saving the session returned by SpotifyAuth.authorize to asyncStorage.

When I try to reinitialise the session by passing that saved token to SpotifyRemote.connect I get this Error: Spotify does not appear to be installed. Note: You must whitelist the 'spotify' URL scheme in your info.plist

My info.plist does include the whitelisting as per the IOS SDK docs:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>spotify</string>
</array>

P-Russell avatar Mar 01 '21 11:03 P-Russell

Hmm interesting. I haven't actually gotten around to this use case yet but I've been hoping to. A few questions.

Is this happening on iOS / Android or both?

Which version of the package are you using?

cjam avatar Mar 10 '21 18:03 cjam

Same issue on iOS. I am using react-native-spotify-remote v0.3.5 I am getting accessToken throught auth.getSession() and auth.authorize(), but I am facing this issue when I call remote.connect()

FYI are there any way to get user playlists (v1/me/playlists) in this library?

eo-sdev avatar Apr 14 '21 18:04 eo-sdev

Same issue on iOS. I am using react-native-spotify-remote v0.3.5 I am getting accessToken throught auth.getSession() and auth.authorize(), but I am facing this issue when I call remote.connect()

FYI are there any way to get user playlists (v1/me/playlists) in this library?

What I've done as far as getting user playlists and other data is take the session access token and couple it with the web api, its bit more work, but it does offer a wider set of tools.

codeCasa avatar Apr 14 '21 20:04 codeCasa

@P-Russell


scopes: [
            ApiScope.AppRemoteControlScope,
            ApiScope.StreamingScope,
            ApiScope.PlaylistModifyPrivateScope,
            ApiScope.PlaylistReadPrivateScope,
            ApiScope.PlaylistModifyPublicScope,
        ]

...
    public connect = async (): Promise<boolean> => {
        try {
            await SpotifyAuth.endSession();
            const session = await SpotifyAuth.authorize(this.spotifyConfig);
            this.appSettings.saveBoolean(Settings.DidConnectToSpotify, true);
            await this.appSettings.saveSecureAsync(Settings.SpotifyAccessToken, session.accessToken);
            await this.appSettings.saveSecureAsync(Settings.SpotifyRefreshToken, session.refreshToken);
           ...
            return true;
        } catch (err) {
            return false;
        }
    };

    public connectRemote = async (): Promise<boolean> => {
        try {
            if (await SpotifyRemote.isConnectedAsync()) {
                return true;
            }
            const tokenString = await this.appSettings.getSecureAsync(Settings.SpotifyAccessToken);
            if (!tokenString || tokenString.length === 0) {
                return false;
            }
            await SpotifyRemote.connect(tokenString);
            return await SpotifyRemote.isConnectedAsync();
        } catch (ex) {
            console.log("failed to connect", ex);
            return false;
        }
    };

Also it seems that Spotify must be actively playing music if your app is to connect while it is in the background.

codeCasa avatar Apr 14 '21 21:04 codeCasa

One question more. Should I add spotify into info.plist as url scheme?

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>spotify</string>
</array>

eo-sdev avatar Apr 15 '21 03:04 eo-sdev

One question more. Should I add spotify into info.plist as url scheme?

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>spotify</string>
</array>

Yes you should. That is what I have as well.

codeCasa avatar Apr 15 '21 03:04 codeCasa

I tried it, but still same issue. Should I install the Spotify App in my phone?

eo-sdev avatar Apr 15 '21 04:04 eo-sdev

hey @denis0324, the new Spotify SDK's (i.e. the ones that this library wraps) provide an api to control the Spotify app on the phone from another app, so you will definitely need the app installed.

@codeCasa Also it seems that Spotify must be actively playing music if your app is to connect while it is in the background.

This is a limitation in iOS in due to how it aggressively backgrounds apps that aren't doing anything (which in turn disconnects this library)

Also, in my experience as with others here. Using this library in conjunction with the web api yields the best results. Using this library to control the music playing and state of spotify on the phone, but using the web api to get song / playlist data.

cjam avatar Apr 15 '21 13:04 cjam

Hi, @cjam Thanks for your reply.

Yes, I noticed that the new Spotify SDK is very difference with old one (I mean rn-spotify-sdk) And it seems that the remote connection is only available when the Spotify plays music. (iOS)

It's because I am getting the below issue when stop music in the Spotify.

Connection attempt failed. Ensure the Spotify app is installed, and try to reconnect. Stream error.
Reconnect the transport to the Spotify app. The operation couldn't be completed. Connection refused.

And it's succeed when play music in the Spotify.

Thanks.

eo-sdev avatar Apr 15 '21 16:04 eo-sdev

Yea @denis0324 unfortunately it's a limitation of the underlying SDK on iOS. I generally use the authorize and play flow to wake Spotify back up if it gets backgrounded. Not sure of a better solution at this point unfortunately.

cjam avatar Apr 16 '21 03:04 cjam

Hi, @cjam I am facing the same issue.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>spotify</string>
</array>

I added the above property in my info.plist, but still getting the error.
I run the app in iPhone Simulator.

const session = await SpotifyAuth.authorize(spotifyConfig);
await SpotifyRemote.connect(session.accessToken);
await SpotifyRemote.playUri('spotify:track:6IA8E2Q5ttcpbuahIejO74');
await SpotifyRemote.seek(58000);
    
I am just fetching the access token and try to playing track.

Bhavin-hyperspace avatar Jun 28 '22 07:06 Bhavin-hyperspace

@Bhavin-hyperspace Hey, i'm also just fetching the token and trying to play the track. Did you find any solutions?

TSB1999 avatar Aug 19 '22 15:08 TSB1999

'm also just fetching the token and trying to play the track. Did you find any solutions?

@TSB1999 i am not able to find any solution. Did you get same error?

Bhavin-hyperspace avatar Sep 03 '22 09:09 Bhavin-hyperspace

@Bhavin-hyperspace actually i did manage to solve the issue. But I'm using an M1 Mac and the configuration may be slightly different.

But basically I don't think you can use the accessToken from the web API.

With iOS for example, you need to follow all the steps in "configure info plist". Especially step two where they talk about URL schemes.

Essentially, you need to create a URL scheme that matches the redirectURL before the ://

Basically, read this document (https://developer.spotify.com/documentation/ios/quick-start/) and ensure you follow the steps in "configure info plist" very carefully.

The web api access token won't work with this library because it needs to actually be redirected back via deep links. So this has to be confirmed in the info plist as explained above.

TSB1999 avatar Sep 03 '22 15:09 TSB1999