Problem programmatically accessing the iTunes libr

2019-09-12 06:58发布

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条回答
祖国的老花朵
2楼-- · 2019-09-12 07:47

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.

查看更多
登录 后发表回答