BUG iOS) I found an orientation iOS16 issue in the iOS simulator

When I checked the iOS application that I created, which worked fine until iOS15, with the simulator of iOS16 (in New Xcode 14.0), the orientation of the screen became strange and the following message appeared in the console. (from UIKit?)

[Orientation] BUG IN CLIENT OF UIKIT: Setting UIDevice.orientation is not supported. Please use UIWindowScene.requestGeometryUpdate(_:slight_smile:

The code for JUCE that seems to apply is
in juce_ios_UIViewComponentPeer.mm
void Desktop::allowedOrientationsChanged()

Please give me suggestions on how to fix it

We have this problem too I’m afraid. Also, it is a problem for iOS16 in general - i.e. on actual devices as well as the simulator. JUCE will need an update to support orientation changes on iOS16.

Here are some details:

In the file juce_ios_UIViewComponentPeer.mm, specifically in the function void Desktop::allowedOrientationsChanged(), the following line…

[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

is now deprecated in iOS16.

Some more info here:
https://developer.apple.com/forums/thread/707735

I have read that the solution may involve calling requestGeometryUpdateWithPreferences on the window scene. So far I’ve been unable to make this work, however.

A fix to this would be greatly appreciated as it breaks orientation support on all devices that update to iOS16.

Thanks in advance,
Adam

Thanks for reporting, the new API is now used on devices running iOS 16+, as long as your app is built using a version of Xcode that includes the iOS SDK 16 or newer.

1 Like

Thank you.
I applied the patch immediately to see how it works, and it works.
I also understand that DeploymentTarget >= iOS16.0 is required to use this patch (UIWindowScene.Geometry is a new API).
From now on, the Apple store will require me to offer multiple OS versions of my app. I don’t understand why Apple does this.

This change should work correctly on iOS 16 and earlier, so there shouldn’t be any need to distribute multiple copies of your app.

I understand what reuk-san is saying even in the source code.

The Xcode’s technique of using a “low DeploymentTarget” to support older OS versions and the latest OS at the same time no longer works. about it.

Hey @reuk, I’m a bit confused about this fix, maybe you could help me understand.
For example this code works perfectly on iOS 15.5: (Its the GUI application start project, starting with all orientations support)

//==============================================================================
MainComponent::MainComponent()
{
    setSize (600, 400);
  
// here we limit the orientation to upright
    juce::Desktop::getInstance().setOrientationsEnabled(juce::Desktop::upright);
}

.
.
.
.

void MainComponent::mouseDown (const juce::MouseEvent& event)
{
//when clicking on the screen, orientation should change to landscape
    juce::Desktop::getInstance().setOrientationsEnabled(juce::Desktop::rotatedClockwise);
}

When build to iOS 15.5, the app starts in portrait, and after clicked the orientation changes to landscape, which I believe is the desired behavior.

When build to iOS 16.2, the first call to Desktop::getInstance().setOrientationsEnabled is working as expected and the app also starts in portrait mode, but on the second call, we get assertion:

None of the requested orientations are supported by the view controller. 
Requested: landscapeLeft; Supported: portrait
JUCE Assertion failure in juce_ios_UIViewComponentPeer.mm:1941

So I understand from the way Desktop::allowedOrientationsChanged() works, that the only way for setOrientationsEnabled to work is if the desired orientation is already included in the allowed orientations,is that correct? Or is it a bug?
And if so, is there’s a way I could reproduce the 15.5 behavior?
What we need for this App is to skip from portrait to landscape and back, is it still possible?
Thanks for the time and effort :pray:

Thanks for reporting. It looks like, in iOS 16.2, we also need to call setNeedsUpdateOfSupportedInterfaceOrientations before calling requestGeometryUpdateWithPreferences. I’ll push that change shortly.

It also seems that when an iPad app supports all orientations and doesn’t require fullscreen, programatically setting a new orientation will fail. This was also the case on iOS 15, but the error message on iOS 16 (“The current windowing mode does not allow for programmatic changes to interface orientation.”) isn’t very descriptive and had me scratching my head for a while…

2 Likes

Yes, that’s working :slight_smile:
Thanks for the fast reply.

1 Like

We’ve added that change here, so hopefully you won’t need to call setNeedsUpdateOfSupportedInterfaceOrientations manually anywhere if you were using that as a workaround:

Please try updating and check whether the issue is resolved for you.