Urkman
Urkman

Reputation: 1318

Getting Genre list on iOS7

I try to get the list of genres on my iPhone 5S with iOS 7.0.3 using this code:

    MPMediaQuery *query = [MPMediaQuery genresQuery];
    for (MPMediaItemCollection *item in [query collections]) {
        NSLog(@"%@", [[item representativeItem] valueForProperty: MPMediaItemPropertyGenrePersistentID]);
        NSLog(@"%@", [[item representativeItem] valueForProperty: MPMediaItemPropertyGenre]);
    }

The problem is, that this code get the correct count of genres, but not the correct names. Some of the names and id's are show twice and some others are missing.

The code works fine on an iPod with iOS 6.1.3.

Anybody with an tipp for me?

Thanks, Stefan

Upvotes: 0

Views: 807

Answers (1)

Bryan Luby
Bryan Luby

Reputation: 2567

There seems to be a bug when dealing with the representativeItem of a collection. For example, the genres Jazz, Jazz-Fusion, and Jazz-Rock all get returned as Jazz when querying the representativeItem for the genre title property. As a workaround, get the firstObject of the items array to get the correct information:

MPMediaQuery *query = [MPMediaQuery genresQuery];
for (MPMediaItemCollection *item in [query collections]) {
    NSLog(@"%@", [[item.items firstObject] valueForProperty: MPMediaItemPropertyGenrePersistentID]);
    NSLog(@"%@", [[item.items firstObject] valueForProperty: MPMediaItemPropertyGenre]);
}

Upvotes: 1

Related Questions