当我尝试使用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 Simulator根本不支持MPMediaPickerController?如果没有,除了在物理设备上运行外,还有其他选择?
解决方法
MPMediaPickerController在模拟器中不起作用.苹果在“你好音乐播放器”下的“
iPod Library Access Programming Guide”中注明.笔记说:
Note: To follow these steps you’ll need a provisioned device because
@H_301_14@
the Simulator has no access to a device’s iPod library.为了防止断言,您可以随时检查是否可以访问代码(代码为使用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]; }