0

I'm building an app in Xcode that will present users with a daily song title. The songs are from several different streaming services including Apple Music, Spotify, and Soundcloud. When the user presses my "Listen Now" button, I want them to be taken directly to the song on whichever streaming service the song lives on.

How can I make the path of the "Listen Now" button change daily? Example: today "Listen Now" should take them to Spotify. Tomorrow it should take them to Apple Music.

I'm using Xcode 10.2. I have my song titles stored in a Json. I can get my "Listen Now" button to open Spotify, but I can't figure out how to incorporate more streaming services into the same button.

@IBAction func listenTapped(_ sender: UIButton) {

    let spotifyApplication = UIApplication.shared
    let spotifyAppPath = "spotify://"
    let spotifyAppUrl = URL(string: spotifyAppPath)!
    let spotifyWebUrl = URL(string: "https://play.spotify.com")!

    if spotifyApplication.canOpenURL(spotifyAppUrl) {

        spotifyApplication.open(spotifyAppUrl, options: [:], completionHandler: nil)
    } else {
        spotifyApplication.open(spotifyWebUrl)
    }


}

I expect the "Listen Now" button to send my users to whichever streaming service the daily song title lives on. If today's song is on Spotify, the "Listen Now" button should send the user to the song on Spotify. If tomorrow's song is on Apple Music, the "Listen Now" button should send the user to the song on Apple Music tomorrow.

  • How do you know which service to send the user to, or which service has any particular song? – ZGski Jul 09 '19 at 19:27
  • @ZGski thank you for your response, that's a great question. For now, this is a very manual process where I handpicked the songs from their respective streaming services. So I know definitively where the songs lives. – Brettster Jul 10 '19 at 18:57

0 Answers0