【问题标题】:AVPlayerViewController crashing when tapping media selection button in landscape on iPhone plus device在 iPhone plus 设备上点击横向媒体选择按钮时,AVPlayerViewController 崩溃
【发布时间】:2017-08-10 10:13:41
【问题描述】:

标题几乎描述了所有内容,但这里详细... 要在我的应用程序中播放视频,我使用的是 AVPlayerViewController,我以模态方式呈现

let player = AVPlayer.init(url: url)
let playerViewController = AVPlayerViewController.init()
playerViewController.player = player
parentViewController.present(playerViewController, animated: true, completion: {...})

一切正常,视频全屏播放,我可以将设备旋转为横向和纵向...仍然一切顺利。

当我点击右下角的对话气泡以更改音频或字幕设置时,这种 UIAlertController 以纵向模式显示(iPhone 7 plus 纵向):

在横向模式下点击相同的按钮时,它看起来像这样(基本相同,但会以纵向显示,iPhone 7 横向):

在 iPad Air 2 上以横向方式执行相同操作如下所示:

现在的实际问题:在 6/6s/7 PLUS 设备上以横向模式播放电影并点击对话气泡时,应用程序崩溃!这是调试器输出和堆栈跟踪中出现的内容:

2017-08-10 12:08:18.683184+0200 MyApp[27739:6396143] [Assert] transitionViewForCurrentTransition 未设置! (<_uifullscreenpresentationcontroller:>)

对我来说,它看起来像一个 Apple 错误,因为我在这里没有做任何特别的事情(至少我是这么认为的)并且因为只有在使用 plus 设备时才会显示崩溃,这是唯一具有紧凑和组合的设备常规尺寸类。

有人知道这里发生了什么吗?

【问题讨论】:

  • 我面临同样的问题,您找到解决方案了吗?
  • @karthikeyan 看看我的回答

标签: ios crash landscape size-classes avplayerviewcontroller


【解决方案1】:

我遇到了同样的问题,我用AppDelegate.m中的以下代码修复了它

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    for (UIView *transitionView in window.subviews) {
        if ([transitionView isKindOfClass:NSClassFromString(@"UITransitionView")]) {
            for (UIView *subView in transitionView.subviews) {
                id nextResponder = [subView nextResponder];
                if ([nextResponder isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
                    return UIInterfaceOrientationMaskAll;
                }
            }
        }
    }
    return   (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationLandscapeLeft);
}

【讨论】:

  • 我还是崩溃了。
【解决方案2】:

这里是 Swift 版本:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {

    if let window = window, let transitionViewClass = NSClassFromString("UITransitionView") {
        for transitionSubview in window.subviews where transitionSubview.isKind(of: transitionViewClass) {
            for subview in transitionSubview.subviews {
                if
                    let avPlayerClass = NSClassFromString("AVFullScreenViewController"),
                    let nextResponder = subview.next,
                    nextResponder.isKind(of: avPlayerClass) {
                    return .all
                }
            }
        }
    }

    return .portrait
}

这对我有用!!

【讨论】:

  • 我还是崩溃了。
【解决方案3】:

我尝试了@qinghe.zhang 的解决方案。但崩溃并没有完全修复。当我退出AVMediaSelectionViewControllerAVFullScreenViewController 返回纵向模式。将设备保持在横向并将视频保持在纵向模式,然后再次单击媒体按钮,同样的崩溃发生了。所以我对@qinghe.zhang 的解决方案做了一点调整。当nextResponderAVFullScreenViewController 时,返回当前方向而不是 UIInterfaceOrientationMaskAll。并且AVMediaSelectionViewController 将以纵向模式显示以避免这种崩溃。

 for (UIView *transitionView in window.subviews) {
        if ([transitionView isKindOfClass:NSClassFromString(@"UITransitionView")]) {
            for (UIView *subView in transitionView.subviews) {
                id nextResponder = [subView nextResponder];
                if ([nextResponder isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
                    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
                    return 1 << orientation;
                }
            }
        }
    }
    return UIInterfaceOrientationMaskPortrait;

【讨论】:

  • 我在 iPhone 8+ / iOS 12.1.3 上遇到了这个崩溃。我发现对@qinghe.zhang 的这种修改是不必要的。但是,我看到您在 2019 年发布了这篇文章,并且想知道您使用的是什么设备/iOS?
【解决方案4】:

这一定是 iOS 10 的错误,因为我无法再使用 iOS 11 重现此问题。

【讨论】:

  • 我只获得 iOS 11 设备,而不是 iOS 10
  • 在 iOS 12 上经验丰富。
猜你喜欢
  • 2017-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-10
  • 2021-03-13
  • 1970-01-01
  • 1970-01-01
  • 2012-09-17
相关资源
最近更新 更多