Say you have an iOS app and you want to deeplink into Spotify, if it’s installed on the phone, to play a track. You can do that like this.

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func deeplinkPressed(_ sender: Any) {

        if isSpotifyInstalled() {
            UIApplication.shared.openURL(NSURL(string:"spotify:track:06TY7FCbeT7Lu39oZ0IEsN")! as URL)
        } else {
            UIApplication.shared.openURL(NSURL(string:"https://open.spotify.com/track/06TY7FCbeT7Lu39oZ0IEsN")! as URL)
        }

    }

    func isSpotifyInstalled() -> Bool {
        return UIApplication.shared.canOpenURL(NSURL(string:"spotify:")! as URL)
    }
}

First you need to see if Spotify is installed on the phone. You can do that by trying to open the Spotify URLScheme in the isSpotifyInstalled() method.

Then, before you can deeplink in, you need to white list the Spotify app in your plist entries.

Screen Shot 2016-12-20 at 11.07.04 AM.png

With that in place, you should now be able to deeplink into Spotify with a Spotify URL. If Spotify is not installed, then open a standard web view with the open.spotify URL.

Links that help:
http://stackoverflow.com/questions/30987986/ios-9-not-opening-instagram-app-with-url-scheme

Advertisements