UPDATE: No longer occurs on iOS 6 beta 1
I am currently working on adapting an existing iOS 4 application with the new iOS 5 SDK. I found a new crash when presenting a UIWebView in a modal view controller that reads a Youtube video.
Starting to read the video is fine, but when I try to set it in full screen, I get the following exception :
Exception: UIViewControllerHierarchyInconsistency,
child view controller:<UIViewController: 0x6aef180>
should have parent view controller:<WebViewController: 0x6a706c0>
but requested parent is:<MPInlineVideoViewController: 0x6ae5d40>
Here is how I instanciate and present my modal view controller in my main view controller :
- (IBAction)buttonReleased:(id)sender
{
WebViewController *webVC = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]];
webVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
webVC.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:webVC animated:YES];
}
I use the UIModalPresentationPageSheet as modalPresentationStyle, when I set this value to UIModalPresentationFullScreen, the error no longer occurs.
In my modal WebViewController, here is how I load my Youtube video :
- (void)viewDidLoad
{
[super viewDidLoad];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=bDlm3eLRut0"]]];
}
Any ideas on this problem ? I can provide a full sample code that isolates this crash if needed.
Thanks !
Those console warnings are due to the audio components on your Mac being loaded. It's a Simulator and not an Emulator—the simulator is still a Mac OS X app so when using audio it loads all of the audio kexts that Mac apps load. It happens when I test audio streaming for my Bandcamp app Kumbaya in the simulator. If you don't want to see those issues, test on the device.
If you'd like, you can wrap your audio methods with:
#if ! TARGET_IPHONE_SIMULATOR
#endif
to disable them in the simulator.
We resolved this by basically implementing our own modal view transitions. It was actually pretty easy to do; I built it in about 4 hours.
You can also avoid the crash if you are presenting it modally full screen. Sheets, either form sheets or page sheets, are the causes of the crash.
I had the same issue in my application. It turned out I set the wrong rootViewController
in UIWindow
.
I have the following view controller hierarchy in my NIB:
Navigation Controller
+- Main View Controller
The rootViewController
outlet of the UIWindow
was set to Main View Controller
instead to Navigation Controller
. As soon as I changed the outlet to Navigation Controller
the UIViewControllerHierarchyInconsistency
exception no longer occurred.
We had the same issue here while playing video on iPad in a pageSheet modal controller.
It only happened for us
- IOS 5 (5.0 + 5.1)
- iPad in landscape mode
- Webview controller presented modally and loading a video resource in PageSheet / FormSheet mode
We've fixed it by forcing the controller in Full screen for IOS 5. Works fine now.
//Fix for IOS 5.0 issues with playing video in pageSheet
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 6.0)
{
[controllerToDisplayModally setModalPresentationStyle:UIModalPresentationPageSheet];
}
else
{
[controllerToDisplayModally setModalPresentationStyle:UIModalPresentationFullScreen];
}
[controllerToDisplayModally setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:controllerToDisplayModally animated:YES completion:nil];
来源:https://stackoverflow.com/questions/7905258/ios5-exception-on-uiwebview-in-modal-uiviewcontroller-playing-youtube-video