Objective C: Getting MPMediaItem 'Favorite'

2019-04-02 01:20发布

问题:

I was looking at Apple's documentation, and I cannot seem to find a way to get whether or not an MPMediaItem is a 'favorite' track or not. See screenshot below, with the pink heart.

How can one get this property? I know since it's a new feature, it's availability would be limited to iOS 8.4 or later.

Here's some code I'm using to get other properties from MPMediaItems, via the music picker:

- (void) processMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
            //iterate through selected songs
            if (mediaItemCollection) {
                NSArray *allSelectedSongs = [mediaItemCollection items];

                for(MPMediaItem *song in allSelectedSongs)
                {
                    NSURL *songURL = [song valueForProperty:MPMediaItemPropertyAssetURL];
                    NSNumber *ident = [song valueForProperty:MPMediaEntityPropertyPersistentID];
                    NSString *identString = [BukketHelper convertULLToNSString:ident];
                    NSNumber *isCloud = [song valueForProperty:MPMediaItemPropertyIsCloudItem];
                }

 //do other stuff here
}

Anyone have ideas?

回答1:

You have to use Apple Music API to get or set users's Like/Dislike to a song like this:

GET https://api.music.apple.com/v1/me/ratings/songs/{id}

From: Apple Docs link