Are you testing on iOS 16 beta? This is mentioned as bug on iOS 16 beta.
https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-16-release-notes
Although it mentioned is fixed on iOS 16 Beta 4, I still experience the same.
This discussion is similar as yours.
https://developer.apple.com/forums/thread/707735
Post
Replies
Boosts
Views
Activity
Same scenario as you. In iOS beta 3, they mentioned:
Attempting to set an orientation on UIDevice via setValue:forKey: isn’t supported and no longer works. (93367651)
In iOS beta 4 which is released yesterday, they mentioned it is Fixed.
However, the issue still the same on iOS 16 beta 4
[Orientation] BUG IN CLIENT OF UIKIT: Setting UIDevice.orientation is not supported. Please use UIWindowScene.requestGeometryUpdate(_:)
My code is working fine on older iOS versions too.