Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS5: Exception on UIWebView in modal UIViewController playing Youtube video

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 !

like image 802
Thomas Desert Avatar asked Oct 26 '11 15:10

Thomas Desert


2 Answers

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.

like image 112
james_womack Avatar answered Oct 31 '22 12:10

james_womack


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.

like image 2
Steve Streza Avatar answered Oct 31 '22 10:10

Steve Streza