Deep link to Apple Music library playlist from Swift (iOS) app

Hi there,

The following code snippet will open Apple Music on an iOS device to a catalog playlist, using the globalId.

if let url = URL(string: "music://music.apple.com/us/playlist/\(playlist!.attributes.playParams.globalId!)") {
            await UIApplication.shared.open(url)

What I'd like to do is open Apple Music using the standard ID, as I don't want to force users to make a playlist public in order to link to it from my app.

This requires the above code to use a library link instead of a catalog link.

I've tried various permutations of the url, but I can't seem to find the secret sauce.

Any tips, would be most appreciated.

Thanks!

Replies

It turns out you can open Apple Music to the user's library, using /library/ in the path, but it seems that's as deep as it will link.

This works

let urlString = "music://music.apple.com/library"
                                        if let url = URL(string: urlString) {
                                            await UIApplication.shared.open(url)
                                        }

This opens Apple Music to the user's library.

This doesn't

let urlString = "music://music.apple.com/library/playlists"
                                        if let url = URL(string: urlString) {
                                            await UIApplication.shared.open(url)
                                        }

This doesn't

let urlString = "music://music.apple.com/library/playlist/\(playlistID)"
                                        if let url = URL(string: urlString) {
                                            await UIApplication.shared.open(url)
                                        }

The above two open Apple Music, which then displays an error: "An Error Occurred" with a Try Again button

Hello @Kimfucious,

Thank you for your question about deep links into the Library tab of the Apple Music app on iOS.

First of all, I need to make an important point: PlayParameters should be treated as opaque objects, and you shouldn't rely on any specific fields in that object. That's why in MusicKit for Swift, it is effectively opaque, and documented as such:

An opaque object that represents parameters to initiate playback of a playable music item using a music player.

That said, it seems to me like the Music app on iOS doesn't support such deep links.

Could you file a ticket on Feedback Assistant outlining your enhancement request as well as explaining your use-case?

Thank you very much in advance.

Best regards,

  • Thanks @JoeKun, for your follow up.

    While I don't quite know what "opaque" actually means, I think you've confirmed that the Apple Music app does not presently support what I'm trying to do.

    I shall follow your advice and file a ticket.

Add a Comment