7

I'm pretty sure there must be a way to launch spotify iphone app from my own app. I've seen SMP app (share my playlist) doing something very similar when pushing playlist into spotify app.

I guess it should be by using something like:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"spotify://search:muse"]];

As you can see, I want to be able to make spotify search for a specific keyword. The problem is I don't really know the spotify url scheme, if there is such thing available.

I've been searching in the web, in spotify developer website, etc. but nothing comes up...

Matthias Benkard
  • 15,497
  • 4
  • 39
  • 47
Mariano Latorre
  • 719
  • 1
  • 10
  • 21
  • try spotify:search:muse (from http://www.spotify.com/se/blog/archives/2008/01/14/linking-to-spotify/) – Nick Moore Apr 11 '12 at 18:49
  • great! it worked, but it didn't landed in the spotify search tab with the results. If think there should be a way to tell spotify app to do so. Do you know if its possible? thanks – Mariano Latorre Apr 12 '12 at 09:41

2 Answers2

12

I have run into a similar need in an app. My solution was to create a client that hits the Spotify API to return either XML or JSON of the search. For instance, if you want Muse, you would hit the API with the following URL:

http://ws.spotify.com/search/1/artist?q=muse

From the XML or JSON, you'll be able to extract the link to the particular artist within their URL scheme:

spotify:artist:12Chz98pHFMPJEknJQMWvI

Chop off the spotify:artist: portion and append that onto a Spotify artist link:

http://open.spotify.com/artist/12Chz98pHFMPJEknJQMWvI

Then, using the Spotify URL scheme and UIApplication, you can open the Spotify app to that particular artist's page:

[[UIApplication sharedApplication] openURL:
   [NSURL URLWithString:
       @"spotify://http://open.spotify.com/artist/12Chz98pHFMPJEknJQMWvI"]];

Note, using URL schemes to access features of another app is generally undocumented and can be a fragile endeavor. If Spotify in the future decides to change anything about this, it will break this functionality without warning.

Dre
  • 4,298
  • 30
  • 39
Sean Kladek
  • 4,396
  • 1
  • 23
  • 29
2

The quick fix I made was to remove the urlscheme that was added to the original uri. so you'll be calling the uri directly.

which is 'spotify:artist:4gzpq5DPGxSnKTe4SA8HAU' or 'spotify:track:1dNIEtp7AY3oDAKCGg2XkH'

UIApplication.shared.openURL("spotify:artist:4gzpq5DPGxSnKTe4SA8HAU") or UIApplication.shared.openURL("spotify:track:1dNIEtp7AY3oDAKCGg2XkH")

this fix is for the crash when calling the old urlscheme from v6 and above.

eNeF
  • 3,241
  • 2
  • 18
  • 41