[[UIDevice currentDevice] setValue:] orientation issue in iOS 16

i am trying to change the orientation for user event in iOS 16 Beta 5.

[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];

but i am getting below error in the log

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

but it's working in iOS 15 and below.

As per Apple beta 4 release notes UIKit UIDevice orientation issue is been fixed.


https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-16-release-notes

Fixed: Attempting to set an orientation on UIDevice via setValue:forKey: isn’t supported and no longer works. (93367651)


i am not sure why its not working for me.

i am using XCode Version 14.0 beta 5 (14A5294e) and iOS 16.0 Beta 5

since this orientation feature already implemented in our Live app we are currently not expecting code change.

Please suggest.

In general if you see code that uses -setValue:forKey: instead of calling a setter or assigning to a property, you should be very suspect of that code – it is likely doing something that is not supported and may break in a future release. For UIDevice and the "orientation" key, iOS 16 is that release.

If a class is not specifically documented to use -setValue:forKey: as part of its interface, then code that is doing so is likely trying to take advantage of implementation details of that class that are subject to change.

As per Apple beta 4 release notes UIKit UIDevice orientation issue is been fixed.

Fixed: Attempting to set an orientation on UIDevice via setValue:forKey: isn’t supported and no longer works. (93367651)

i am not sure why its not working for me.

It’s not going to work. Unfortunately the release note could be worded a bit more clearly. Here’s how to understand it:

“It was a bug that this setValue:forKey: technique ever had an effect. It should never have been used by any apps. This behavior has now been fixed so that the setValue:forKey: technique no longer has an effect."

All those sites, articles, posts, gists, etc., that document this setValue:forKey: technique... they are wrong and always were. See also this thread where @eskimo declared it unsupported, years ago.

[[UIDevice currentDevice] setValue:] orientation issue in iOS 16
 
 
Q