尝试以下代码:
// 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 *representativeItemReleaseDate = [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);
}
在所有情况下,我对NSDates都没有... 但在iPod库中我可以看到日期,因此必须提供信息。 获得它的正确方法是什么?
答案 0 :(得分:19)
我还找到了如何获取'年份'信息(我需要的信息),但不幸的是没有记录:
MPMediaItem *item = ...;
NSNumber *yearNumber = [item valueForProperty:@"year"];
if (yearNumber && [yearNumber isKindOfClass:[NSNumber class]])
{
int year = [yearNumber intValue];
if (year != 0)
{
// do something with year
}
}