Opening spotify app from my iphone app

后端 未结 2 801
不知归路
不知归路 2020-12-08 23:56

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

相关标签:
2条回答
  • 2020-12-09 00:49

    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.

    0 讨论(0)
  • 2020-12-09 01:00

    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.

    0 讨论(0)
提交回复
热议问题