iPad orientation returns unknown values

In iOS 13, the statusBarOrientation has been deprecated. The new preferred way of getting this orientation is

let orientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation


If I add [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; the orientation will be correct even in OpenGL rendering mode. UIDeviceOrientationUnknown orientation is sometimes returned but only for short time.


There are situations where the accelerometer can’t get an accurate read on the orientation, such as when the device is held flat. You should still be able to get the current orientation using:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

Tags:

Ipad