2015-06-03 31 views
1

我想从iPod库中获取多首艺术家曲目。下面的代码让我得到具体的艺术家曲目一样 -是否有任何方法可以一次从iPod库中搜索多个艺术家曲目。

MPMediaQuery *query = [[MPMediaQuery alloc] init]; 
    [query addFilterPredicate: [MPMediaPropertyPredicate 
           predicateWithValue:@"Lady Gaga" 
           forProperty: MPMediaItemPropertyArtist]]; 
[query setGroupingType: MPMediaGroupingAlbum]; 

    NSArray *albums = [query collections]; 

是有可能得到多位艺术家追踪像Lady Gaga的&阿肯轨道只有单一的查询predicateWithValue通过sepearted; OR/
例 -

[query addFilterPredicate: [MPMediaPropertyPredicate 
            predicateWithValue:@"Lady Gaga/ Akon" 
            forProperty: MPMediaItemPropertyArtist]]; 

请帮助我如何能满足我的要求。

回答

0

你可以使用聚合运算符IN(如@"attribute IN %@", aCollection)和整个collections阵列过滤的NSPredicate

NSArray *artists = @["Lady Gaga", @"Justin Bieber", @"Selena Gomez"]; 
MPMediaQuery *query = [[MPMediaQuery alloc] init]; 
[query setGroupingType: MPMediaGroupingAlbum]; 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ IN %@", MPMediaItemPropertyArtist, artists]; 
NSArray *albums = [[query collections] filteredArrayUsingPredicate:predicate]; 
+0

嗨skyddict,我用你的代码,但没有得到任何结果,而不是我有这些艺术家在我的设备中的轨道。 –

相关问题