iOS5:模式 UIViewController 中 UIWebView 播放 Youtube 视频时出现异常
更新: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这些控制台警告是由于 Mac 上的音频组件正在加载而导致的。它是一个模拟器,而不是模拟器——模拟器仍然是一个 Mac OS X 应用程序,因此在使用音频时,它会加载 Mac 应用程序加载的所有音频 kext。当我在模拟器中测试 Bandcamp 应用程序 Kumbaya 的音频流时,会发生这种情况。如果您不想看到这些问题,请在设备上进行测试。
如果您愿意,可以将音频方法包装为:
以在模拟器中禁用它们。
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:
to disable them in the simulator.
我们基本上通过实现我们自己的模式视图转换来解决这个问题。实际上这很容易做到;我用了大约 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.
我的申请中也遇到了同样的问题。结果我在
UIWindow
中设置了错误的rootViewController
。我的 NIB 中有以下视图控制器层次结构:
UIWindow
的rootViewController
出口设置为Main View Controller
而不是Navigation控制器。一旦我将出口更改为
Navigation Controller
,UIViewControllerHierarchyInconsistency
异常就不再发生。I had the same issue in my application. It turned out I set the wrong
rootViewController
inUIWindow
.I have the following view controller hierarchy in my NIB:
The
rootViewController
outlet of theUIWindow
was set toMain View Controller
instead toNavigation Controller
. As soon as I changed the outlet toNavigation Controller
theUIViewControllerHierarchyInconsistency
exception no longer occurred.我们在 iPad 上的 pageSheet 模式控制器中播放视频时遇到了同样的问题。
它只发生在我们
模态并在 PageSheet / FormSheet 模式下加载视频资源
我们通过在 IOS 5 中强制控制器处于全屏模式来修复此问题。
现在工作正常。
We had the same issue here while playing video on iPad in a pageSheet modal controller.
It only happened for us
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.