iOS5:模式 UIViewController 中 UIWebView 播放 Youtube 视频时出现异常

发布于 2024-12-11 22:20:04 字数 1322 浏览 0 评论 0原文

更新: iOS 6 beta 1 上不再出现

我目前正在努力使用新的 iOS 5 SDK 来调整现有的 iOS 4 应用程序。 在读取 Youtube 视频的模态视图控制器中呈现 UIWebView 时,我发现了新的崩溃。

开始阅读视频很好,但是当我尝试将其设置为全屏时,出现以下异常:

Exception: UIViewControllerHierarchyInconsistency,
child view controller:<UIViewController: 0x6aef180> 
should have parent view controller:<WebViewController: 0x6a706c0> 
but requested parent is:<MPInlineVideoViewController: 0x6ae5d40>

这是我在主视图控制器中实例化和呈现模态视图控制器的方式:

- (IBAction)buttonReleased:(id)sender
{
    WebViewController *webVC = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]];
    webVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    webVC.modalPresentationStyle = UIModalPresentationPageSheet;
    [self presentModalViewController:webVC animated:YES];
}

我使用 UIModalPresentationPageSheet 作为 modalPresentationStyle,当我将此值设置为UIModalPresentationFullScreen,该错误不再发生。

在我的模态 WebViewController 中,这是我加载 Youtube 视频的方式:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=bDlm3eLRut0"]]];
}

关于这个问题有什么想法吗? 如果需要,我可以提供完整的示例代码来隔离此崩溃。

谢谢 !

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 !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

诺曦 2024-12-18 22:20:04

这些控制台警告是由于 Mac 上的音频组件正在加载而导致的。它是一个模拟器,而不是模拟器——模拟器仍然是一个 Mac OS X 应用程序,因此在使用音频时,它会加载 Mac 应用程序加载的所有音频 kext。当我在模拟器中测试 Bandcamp 应用程序 Kumbaya 的音频流时,会发生这种情况。如果您不想看到这些问题,请在设备上进行测试。

如果您愿意,可以将音频方法包装为:

#if ! TARGET_IPHONE_SIMULATOR
#endif

以在模拟器中禁用它们。

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.

悲欢浪云 2024-12-18 22:20:04

我们基本上通过实现我们自己的模式视图转换来解决这个问题。实际上这很容易做到;我用了大约 4 个小时就建好了。

如果您以全屏方式呈现它,也可以避免崩溃。表单(表单表单或页面表单)是导致崩溃的原因。

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.

浸婚纱 2024-12-18 22:20:04

我的申请中也遇到了同样的问题。结果我在UIWindow中设置了错误的rootViewController

我的 NIB 中有以下视图控制器层次结构:

Navigation Controller
+- Main View Controller

UIWindowrootViewController 出口设置为 Main View Controller 而不是 Navigation控制器。一旦我将出口更改为Navigation ControllerUIViewControllerHierarchyInconsistency异常就不再发生。

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.

薄凉少年不暖心 2024-12-18 22:20:04

我们在 iPad 上的 pageSheet 模式控制器中播放视频时遇到了同样的问题。

它只发生在我们

  • IOS 5 (5.0 + 5.1)
  • iPad 的横向模式
  • Webview 控制器 上
    模态并在 PageSheet / FormSheet 模式下加载视频资源

我们通过在 IOS 5 中强制控制器处于全屏模式来修复此问题。
现在工作正常。

//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];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文