Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...