5

The title is nearly describing everything, but here in detail... To play videos in my app I am using an AVPlayerViewController which I am presenting modally

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

All is working fine, the video plays in full screen and I am able to rotate the device to landscape and to portrait back again ... still everything is running smoothly.

When I tap the speech bubble in the lower right corner to change audio or subtitle setting this kind of UIAlertController shows in portrait mode (iPhone 7 plus portrait): audio & subtitle settings in portrait

When tapping the same button in landscape mode it looks like this (basically the same but will present in portrait orientation, iPhone 7 landscape): audio & subtitle settings launched from landscape but showing in portrait

Doing the same on an iPad Air 2 in landscape looks like this: audio & subtitle settings in landscape on iPad

Now the actual issue: when playing the movie on a 6/6s/7 PLUS device in landscape mode and tapping the speech bubble, the app crashes! This is what is appearing in the debugger output and the stack trace:

2017-08-10 12:08:18.683184+0200 MyApp[27739:6396143] [Assert] transitionViewForCurrentTransition is not set! (<_UIFullscreenPresentationController: 0x7ffe3e586000>) Stack trace

For me it looks like an Apple bug because I am not doing anything special here (at least I think so) and because the crash is only showing when using a plus device, which are the only ones having the combination of compact and regular size class.

Does anybody have an idea what is going on here?

Kai
  • 1,277
  • 2
  • 15
  • 25

4 Answers4

1

I get same issue, I fixed it with the following code in 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);
}
Tim Visée
  • 2,988
  • 4
  • 45
  • 55
0

Here is the Swift version:

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
}

This worked for me!!

David Beleza
  • 93
  • 1
  • 9
0

I tried @qinghe.zhang’s solution. But the crash is not completely fixed. When i quit AVMediaSelectionViewController, AVFullScreenViewController return to portrait mode. Hold the device in landscape and keep video in portrait mode then click media button again, the same crash happened. So i make a little adjustment to @qinghe.zhang’s solution. Return current orientation instead of UIInterfaceOrientationMaskAll when nextResponder is AVFullScreenViewController. And the AVMediaSelectionViewController will present in portrait mode to avoid this crash.

 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;
WPLog
  • 1
  • 3
  • I experienced this crash on an iPhone 8+ / iOS 12.1.3. I found that this modification to @qinghe.zhang was unnecessary. However, I see that you posted this quite recently - in 2019 - and would like to know what device/iOS you were on? – Airsource Ltd May 14 '20 at 10:16
-1

This must have been an iOS 10 bug because I can't reproduce this issue anymore with iOS 11.

Kai
  • 1,277
  • 2
  • 15
  • 25