Trying the following code:
// Per albums
MPMediaQuery *albumsQuery = [MPMediaQuery albumsQuery];
NSArray *collections = [albumsQuery collections];
for (MPMediaItemCollection *collection in collections)
{
NSDate *collectionReleaseDate = [collection valueForProperty: MPMediaItemPropertyReleaseDate];
NSLog(@"collection release date: %@", collectionReleaseDate);
MPMediaItem *representativeItem = [collection representativeItem];
NSDate *representativeItemRe开发者_高级运维leaseDate = [representativeItem valueForProperty: MPMediaItemPropertyReleaseDate];
NSLog(@"representativeItem release date: %@", representativeItemReleaseDate);
}
// Just per item
MPMediaQuery *query = [[MPMediaQuery alloc] init];
NSArray *items = [query items];
for (MPMediaItem *item in items)
{
NSDate *date = [item valueForProperty: MPMediaItemPropertyReleaseDate];
NSLog(@"release date: %@", date);
}
In all cases I get nil's for NSDates... But in the iPod library I can see dates, so the information must be available. What is the correct way to obtain it?
Well, I think I've figured it out. I was thinking that 'Year' column in iTunes corresponds to MPMediaItemPropertyReleaseDate in API - but it's wrong. My items actually weren't having release date info.
I also found how to obtain 'Year' information (which I needed), but unfortunately in undocumented way:
MPMediaItem *item = ...;
NSNumber *yearNumber = [item valueForProperty:@"year"];
if (yearNumber && [yearNumber isKindOfClass:[NSNumber class]])
{
int year = [yearNumber intValue];
if (year != 0)
{
// do something with year
}
}
精彩评论