Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening spotify app from my iphone app

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

like image 298
Mariano Latorre Avatar asked Apr 11 '12 18:04

Mariano Latorre


2 Answers

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.

like image 146
Sean Kladek Avatar answered Nov 18 '22 12:11

Sean Kladek


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.

like image 2
NFerocious Avatar answered Nov 18 '22 12:11

NFerocious