在iOS 模拟器中测试音乐播放功能,使用多媒体选择器 MPMediaPickerController时,出现如下异常信息:
reason: Unable to load iPodUI.framework
模拟器无法访问设备的iPod 库,也就是无法访问设备的音乐库。
要测试这一功能,必须使用实际设备,代码可以改进一下,捕获这一异常信息。
- (IBAction)chooseMusic:(id)sender {
MPMediaPickerController *musicPicker;
musicPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
musicPicker.prompt = @"请选择音乐";
musicPicker.allowsPickingMultipleItems = YES;
musicPicker.delegate = self;
@try {
[self presentViewController:musicPicker 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];
}
}