How unique is MPMediaItemPropertyPersistentID?

How unique is MPMediaItemPropertyPersistentID? Will it work even when synchronizing the list of identifiers with another device connected to the same iTunes account?

I want to implement an iCloud synchronized playlist solution that stores identifiers in a list, and I need to know if this will be possible.

+8
ios objective-c itunes icloud mpmediaitem
source share
4 answers

According to the documentation (my attention) ...

The value of the identifier MPMediaItemPropertyPersistentID is saved through the launch of applications and through synchronization, which do not change the synchronization status of the multimedia element. The value is not guaranteed to be saved in the synchronization / synchronization / synchronization cycle.

As such, given that it will not even persist on this basis, I would be surprised if it was stored on all devices reliably, if at all.

+7
source share

In my understanding, this is impossible. I think this identifier is permanent only for each device. This is not a unique identifier for a specific song in the iTunes Store. This is just the identifier of your own synced songs.

When you read the documentation, you will see how fragile this identifier can be.

"The value cannot be stored in the synchronization / synchronization / synchronization cycle."

So, if you sync your song database with iTunes and maybe delete the song from your iOS device and sync again and return it to your device, you may not get the same ID again for this song. And, of course, not through other devices.

So, I think that what you are trying to do will fail until you get a worldwide identifier for each song in the iTunes directory or your own iTunes directory on the Mac (where the Mac should handle identifiers),

+4
source share

The other answers are a bit vague, so here is the answer from my own experiences and tests:

1) You cannot use MPMediaItemPropertyPersistentID to get an identifier equal between devices.
2) MPMediaItemPropertyPersistentID will change when the device is synchronized with another iTunes library or all music is deleted from the device and then synchronized again.

The identifier is created and saved by iTunes when the song is synced on the device. If it is not synchronized, the identifier is deleted.

+2
source share

If someone else lands here, like me, using a Google search:

I confirmed that middaparka said above after updating my device’s iOS when my music app tried to use persistentIDs before the update. The identifiers changed, and I ended up (involuntarily) listening to many songs from my library that I usually don’t listen to ...

So, I took the advice of middaparka and created a permanent key, excluding hashes from the name, artistName, albumTitle and duration. Building a persistentKey during initialization of the base database will save time later by avoiding multiple string comparisons when typing items in "normal working code."

The persistentKey strategy worked correctly for songs. However, when I made a hash for the albums from the title, artist, and releaseYear, I ran into one collision.

I had two independent albums of different artists, released in 1976. When the hashes for the album title and the artist were exclusive, they cancel each other out. I ended up using a hash for a duration, not a performer, and it worked.

I can finish the refinement of the algorithm to generate persistentKeys later ...

+1
source share

All Articles