以编程方式访问iTunes资料库时出现问题 [英] Problem programmatically accessing the iTunes library

查看:58
本文介绍了以编程方式访问iTunes资料库时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个必须访问iTunes资料库的应用程序.我使用MPMediaQuer从库中检索歌曲,如下所示.

I built an app that must access the iTunes library. I used MPMediaQuer to retrieve songs from the library as in the following.

MPMediaQuery *media = [[MPMediaQuery alloc]init];
NSArray *arr = [media items];

for(MPMediaItem *song in arr)
{
    //To print songs title
    NSString *title = [song valueForProperty:MPMediaItemPropertyTitle];
    NSLog(@"%@", title);
}

但是什么也没印出来!

然后我尝试打印arr数组的计数,结果为0,如下所示.

And I tried to print the count of the arr array and the result is 0 as in the following.

NSLog(@"%D",[arr count]);

我确定iTunes库中有一些歌曲.

And I'm sure there are some songs in the iTunes Library.

因为我在模拟器中进行测试,会发生此问题吗?而且,如果我在设备上测试代码是否可以正常工作?

Do this problem occur because I test in the simulator? And if I test the code on device should it work?

推荐答案

iPod库访问API

The iPod Library Access APIs only works on devices, that's why you aren't getting any result on the iPhone Simulator:

注意:仅可访问iPod库 在设备上而不在模拟器中. 这是因为模拟器没有 访问设备的iPod库.到 使用类开发应用程序 在这项技术中,您需要 预配的iOS设备.

Note: iPod library access works only on devices and not in the Simulator. This is because the Simulator has no access to a device’s iPod library. To develop applications using the classes in this technology, you need a provisioned iOS device.

这篇关于以编程方式访问iTunes资料库时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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