Search code examples
iosapple-music

Swift 2 - sharedApplication() - Apple Music Search Api


I am trying to open from my app Apple Music app using UIApplication.sharedApplication().openURL and search for an artist or having a link opening a related page where the song is.

Is there an api I can use to search on the Apple Music App? Is this possible?

let test = "https://itun.es/gb/RJEL2?i=915794180"
UIApplication.sharedApplication().openURL(NSURL(string:test)!)

If I use that link the app opens up but nothing happens.


Solution

  • If

    let test = "https://itun.es/gb/RJEL2?i=915794180"
    

    contains your search information you can get the contents of the url like such

    let Session = NSURLSession.SharedSession()
    var task = Session.dataTaskWithURL(test, completionHandler: {
       (data, response, error) -> Void in
    
       :
    })
    task.resume()