UIApplicationDelegate supportedInterfaceOrientationsFor not called when supported by Multitasking on iOS

33 views Asked by At

I'm facing an issue with the supportedInterfaceOrientationsFor function in my iOS app. The function is not getting called when the application is supported by the Split View screen(Multitasking).

In my app delegate, I have the following function to handle the application orientation based on a specific requirement:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    // This function is not being called when the app is in Split View
    // Need help in understanding why and how to make it work in Split View
    // Implementation here
    return self.supportedOrientationMask // Placeholder return value
}


I also have a static function in my app delegate to handle application orientation when in session, where I set the supportedOrientationMask property:

static func handleApplicationOrientationWhenInSession(rotate: Bool) {
    let appDelegate = AppDelegate.instance

    if rotate {
        // Enable rotation by setting supported orientation to all
        appDelegate?.supportedOrientationMask = .all
    } else {
        // Set the supported orientation based on the current orientation
        if let currentOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation {
            var value: UIInterfaceOrientationMask

            switch currentOrientation {
            case .portrait:
                value = .portrait
            case .portraitUpsideDown:
                value = .portraitUpsideDown
            case .landscapeLeft:
                value = .landscapeLeft
            case .landscapeRight:
                value = .landscapeRight
            default:
                value = .all
            }

            appDelegate?.supportedOrientationMask = value
            UIDevice.current.setValue(value.rawValue, forKey: "orientation")
        }
    }

    // Attempt to rotate to the device's current orientation
    UIViewController.attemptRotationToDeviceOrientation()
    if #available(iOS 16.0, *) {
        if let topViewController = UIApplication.shared.windows.first(where: { $0.isKeyWindow })?.rootViewController?.topMostVisibleViewController {
            // Use 'window' for your specific needs
            print("Force orientation")
            topViewController.setNeedsUpdateOfSupportedInterfaceOrientations()
            topViewController.view.setNeedsLayout()
            topViewController.view.layoutIfNeeded()
        }
    }
}


Note: If i don't configured supported orientation in Info.plist like below then it works


    <array>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>
    </plist>

0

There are 0 answers