Problem programmatically accessing the iTunes library

无人久伴 提交于 2019-12-13 05:45:53

问题


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);
}

But nothing printed!

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

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

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?


回答1:


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

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.



来源:https://stackoverflow.com/questions/4484731/problem-programmatically-accessing-the-itunes-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!