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

hou*_*oft 12 mpmediapickercontroller ios ios-simulator

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

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'
Run Code Online (Sandbox Code Playgroud)

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

Pie*_*ard 14

MPMediaPickerController在模拟器中不起作用.Apple 在"Hello Music Player"下的" iPod Library Access Programming Guide "中注明了这一点.说明说:

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

为了防止断言,您可以随时检查是否可以在代码中执行此操作(代码如下使用ARC和iOS SDK 5.0).

MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];

[picker setDelegate:self];
[picker setAllowsPickingMultipleItems:YES];
[picker setPrompt:NSLocalizedString(@"Add songs to play","Prompt in media item picker")];

@try {
    [picker loadView]; // Will throw an exception in iOS simulator
    [self presentViewController:picker animated:YES completion:nil];
}
@catch (NSException *exception) {
    [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Oops!",@"Error title")
                                message:NSLocalizedString(@"The music library is not available.",@"Error message when MPMediaPickerController fails to load") 
                               delegate:nil 
                      cancelButtonTitle:@"OK" 
                      otherButtonTitles:nil] show];
}
Run Code Online (Sandbox Code Playgroud)