Is it possible to get the iTunes Store ID for an MPMediaItem? - ios

Is there a way to get the iTunes Store ID for a song from an MPMediaItem?
I'm trying to pull the user's playlists, transfer those to another device, then play the songs using MPMusicPlayerController's setQueueWithStoreIDs. This would require mapping the MPMediaItems to content in the iTunes Store, which is the purpose of iTunes Match, which is included in an Apple Music subscription.
Theoretically, this should be possible for songs that were matched to iTunes content. However, I can't find a property or valueForKey on MPMediaItem or any other class in MPMediaPlayer framework that supports this. The persistentId set of properties are local DB keys and don't tie back to the iTunes content for the item. They don't seem to be the same across devices for the same user either.

This is now possible in iOS 10.3+ using the playbackStoreID instance property on MPMediaItem.
https://developer.apple.com/documentation/mediaplayer/mpmediaitem/2813404-playbackstoreid

Related

How would I be able to uniquely identify a contact in a contact store in a iOS device?

I need someway to uniquely identify a contact in contact store even if the contact is changed.
Is there a way to put code in iOS that is always watching in the background for the contact store to change? That way I can track a contact that I identify with a UUID value and make sure I can always match that specific contact with its UUID value even if the contact changes. If I put it in my app, then the user can close the app, and the app won't receive notifications when the contact store changes? Is there an app extension I can use that would allow me to do this, whether that is the intent of the extension or not?
Perhaps I can use key-value observing. Is it possible to observe the iOS Contacts app or the contacts store of a device using key-value observing? How would I find out? I can't find information on it when I do a search on Google.
I found information about the ABAddressBookRegisterExternalChangeCallback(::_:) function of the Address Book Framework, but that function has been deprecated, and only works with iOS 2.0–9.0. I don't see a function in the Contacts Framework that does what that function does.
Content Added Thursday, March 3, 2022, 12:03 AM:
I need the unique identifier to be saved in a record in a private iCloud database. The objective is to be able to query the database for the record associated with that contact. That would probably mean that the identifier would have to be unique across all iOS devices in existence.Is that so?

Is there still a way to open an iTunes search API trackViewUrl in iTunes Store and not Apple Music?

Following this question we can get a JSON response from the iTunes Search API to direct users to the trackViewUrl. The answer suggested appending &app=itunes to have the iOS device open the URL in the iTunes Store instead of Apple Music, but my test suggests that this doesn't work and Apple Music is still opened.
For instance, the first item of the result of:
https://itunes.apple.com/search?term=pink+floyd%20high%20hopes
shows a trackViewUrl of:
https://music.apple.com/us/album/high-hopes/1067444712?i=1067444898&uo=4,
with the appended request is:
https://music.apple.com/us/album/high-hopes/1067444712?i=1067444898&uo=4&app=itunes
However, this link opens Apple Music on an iOS device.
Is there a way to open the iTunes Store instead? Or another way to open the iTunes Store to a specific track? I need DRM free tracks.
The correct way of doing this now is with StoreKit.

Get Apple Music playlist share URL programmatically by Swift

When sharing playlist in Apple Music app via Email, you can get a URL like this
https://itunes.apple.com/jp/playlist/if-you-like...may-j./idpl.4299b4c5a42048bd850eca538e68ace2?l=en
You will also have an URL when sharing local created playlist.
I would like to know if it is possible to get the URL programmatically on iOS using Swift.
[Effort studied but failed to solve]
Related discussion using link maker does not solve the problem
Apple Music URL Scheme
Query the playlist using: MPMediaQuery.playlists() and enumerated the returned playlist but cannot find any property showing the URL
I'm pretty sure this is not possible. I believe the playlist does not have the idpl value until the user manually presses the share button in iTunes. And, there's nothing in the API to create one.
I set up a proxy and had a look at the requests iTunes makes.
I created a playlist in iTunes and added songs to the playlist. Every song I added made several requests to various endpoints under:
https://ld-6.itunes.apple.com/WebObjects/MZDaap.woa/daap/update No idpl value in any of the responses.
Then I manually hit the share button. A request is made to
https://client-api.itunes.apple.com/WebObjects/MZStorePlatform.woa/wa/lookup with the idpl in the URL.
Now when you add more songs to the playlist, the responses contain the idpl.
From that it seems that the idpl is created on the device when the user touches share.
Probably best to file a radar for Apple to add a share URL property to MPMediaPlaylist.
EDIT: I filed a radar

Launching iTunes Store within App with Search

I'm creating an iOS radio station app, and I can't find a solution to what I thought was a simple problem. If my radio station plays an song/album people want to buy, how can I just launch the iTunes Store and have it open with a search results for that track or album?
I know I can use the Apple Search API to get a json of the search results and parse that for the best search results, and I know I can open the iTunes store with https://itunes.apple.com/ (if I try to append a search string to this, I get the metadata back) or with SKStoreProductViewController if I know the product ID.
But is there a way to simply open the iTunes Store to open with search results for a song or album (or both) without having to evaluate the search metadata and send them to one (perhaps wrong) product?
Thanks!
You can do this using URL Scheme's and a tool called iTunes Link Maker. Documentation can be found for iTunes on Apple's website here
The iTunes URL scheme is used to link to content on the iTunes Music
Store. The iTunes URL format is complicated to construct, so you
create it using an online tool called iTunes Link Maker. The tool
allows you to select a country destination and media type, and then
search by song, album, or artist. After you select the item you want
to link to, it generates the corresponding URL.
http://linkmaker.itunes.apple.com/

Obtaining iTunes ID to an iPod player item

I have an app that interacts with both the iPod player, and the iTunes Store Web Service Search API. Is there a way to obtain the iTunes ID for a song that I retrieve from my user's iPod library (e.g. via MPMusicPlayerController, or MPMediaItem)?
The documentation says that the MPMediaItemPropertyPersistentID is a unique identifier that persists across app launch. This however, seems like it might be a unique local id.
The only solution I can think of is to retrieve the song title and artist from MPMediaItem, then query iTunes to obtain the iTunes ID. Is the iTunes ID stored anywhere locally within the iPod library?
Thanks - I am pretty new to the media framework.
The API documentation does not list a property for MPMediaItem that gives the iTunes Song ID, but it does give all of the information about a song such as the Artist and song name so, as you suggested, you could search the store for that criteria.

Resources