MPMediaQuery仅返回本地项目 [英] MPMediaQuery to return local items only

查看:408
本文介绍了MPMediaQuery仅返回本地项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个只有当前设备上的歌曲的UITableView。

I want to display a UITableView with only the songs that are currently on the device.

如果我查询所有项目,我(显然)会获得所有项目,包括一旦我购买但没有下载。
以下是代码的(部分)

If I query all items I (obviously) get all items, including the once that I purchased but not have downloaded. Here is the (part) of the code

@property (strong, nonatomic) NSMutableArray *songsList;

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    MPMediaQuery *everything = [[MPMediaQuery alloc] init];
    NSArray *itemsFromGenericQuery = [everything items];
    self.songsList = [NSMutableArray arrayWithArray:itemsFromGenericQuery];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.songsList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"TableCellID";
    TableCellTitle *tablecell = (TableCellTitle *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
MPMediaItem *song = [self.songsList objectAtIndex:indexPath.row];

    NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle];
    tablecell.cellSongname.text = songTitle;

    return tablecell;
}

我读过几件涉及

[song valueForProperty:MPMediaItemPropertyIsCloudItem]

但是不能让它像我上面解释的那样工作。
有什么建议吗?

but can't get it to work as I explained above. Any suggestions?

推荐答案

我自己通过在MPMediaQuery之间的viewDidLoad方法中添加以下行来解决它...和NSArray ...

I solved it myself by adding the following line in the viewDidLoad method between MPMediaQuery... and NSArray...

[everything addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithBool:NO] forProperty:MPMediaItemPropertyIsCloudItem]];

这篇关于MPMediaQuery仅返回本地项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆