在iOS模拟器中使用MPMediaPickerController时出现运行时错误

在iOS模拟器中使用MPMediaPickerController时出现运行时错误,ios,ios-simulator,mpmediapickercontroller,Ios,Ios Simulator,Mpmediapickercontroller,当我尝试在iOS模拟器上使用MPMediaPickerController运行应用程序时,会发生以下情况 2012-05-28 22:26:42.416 My App[48426:11f03] Could not load source: 3 2012-05-28 22:26:42.418 My App[48426:11f03] *** Assertion failure in -[MPMediaPickerController loadView], /SourceCache/MediaPlay

当我尝试在iOS模拟器上使用
MPMediaPickerController
运行应用程序时,会发生以下情况

2012-05-28 22:26:42.416 My App[48426:11f03] Could not load source: 3
2012-05-28 22:26:42.418 My App[48426:11f03] *** Assertion failure in -[MPMediaPickerController loadView], /SourceCache/MediaPlayer_Sim/MobileMusicPlayer-1391.72/SDK/MPMediaPickerController.m:86
2012-05-28 22:26:42.419 My App[48426:11f03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to load iPodUI.framework'

这是我的App/Xcode/iOS模拟器中的问题,还是iOS模拟器根本不支持MPMediaPickerController?如果没有,除了在物理设备上运行之外,还有其他选择吗?

MPMediaPickerController在模拟器中不起作用。苹果在“Hello Music Player”下的“”中指出了这一点。便条上说:

注意:要执行这些步骤,您需要配置设备,因为 模拟器无法访问设备的iPod库

为了防止断言,您可以始终检查您是否可以在代码中访问“执行此操作”(下面的代码使用ARC和iOS SDK 5.0)

此外(如果使用故事板),您还可以尝试:

- (IBAction)showPicker:(id)sender
{
#if TARGET_IPHONE_SIMULATOR
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"playerTest"
                                                    message:@"Media picker didn't work in simulator, please run this app on device"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
#else
    [self performSegueWithIdentifier:@"ShowPickerViewSegue" sender:self];
#endif
}

MPMediaPickerController
现在可以在iOS模拟器中工作,无需任何额外的代码更改(至少从iOS 8开始,可能更早)。下面是一个可以演示它的项目:


您必须通过从实际设备复制必要的文件来准备模拟器中的音乐库,最重要的是
mediabrary.sqlitedb
数据库文件。如果您想播放文件和查看艺术品,还必须复制
iTunes\u控件/音乐
购买
艺术品
文件夹(可在
/var/mobile/Media/
中找到)。有关更多详细信息,请参阅此问题:。

我想知道添加try-catch代码是否是成功将应用添加到应用商店的必要条件?如果这不是一个要求,我不打算添加此代码。虽然当时是正确的,但当前的iOS模拟器允许访问音乐库的基本支持;请参阅我的答案了解详细信息。现在这是可能的,请参阅下面的我的答案了解详细信息。
- (IBAction)showPicker:(id)sender
{
#if TARGET_IPHONE_SIMULATOR
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"playerTest"
                                                    message:@"Media picker didn't work in simulator, please run this app on device"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
#else
    [self performSegueWithIdentifier:@"ShowPickerViewSegue" sender:self];
#endif
}