有同樣的問題。例如,我試圖用這樣的代碼
MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query setGroupingType: MPMediaGroupingAlbum];
collections = [query collections];
讓所有相冊(包括視頻),但正如你所說,它錯過了沒有過任何專輯信息的項目。我的解決方案是自己重建相冊集:
MPMediaQuery *query = [[MPMediaQuery alloc] init];
NSArray* a = [query items];
NSMutableArray* lc = [NSMutableArray array];
for (MPMediaItem* mp in a) {
NSString* atitle=[mp valueForProperty:MPMediaItemPropertyAlbumTitle];
NSMutableArray* found = nil;
for (NSMutableArray*l in lc) {
NSString* ltitle=[l[0] valueForProperty:MPMediaItemPropertyAlbumTitle];
if ((!atitle && !ltitle) || [atitle isEqualToString:ltitle]) {
found = l;
break;
}
}
if (found) {
[found addObject:mp];
} else {
[lc addObject:[NSMutableArray arrayWithObject:mp]];
}
}
NSMutableArray* lcc = [NSMutableArray array];
for (NSMutableArray*l in lc)
[lcc addObject:[MPMediaItemCollection collectionWithItems:l]];
collections = [NSArray arrayWithArray:lcc];
當調用+ albumQuery時,分組類型自動設置爲MPMediaGroupingAlbum。 – sharvey 2011-01-04 21:04:20