UIDevice.current.orientation always reporting unknown in iMessage App.

Trying to get the orientation of the device in my iMessage app.


I'm checking UIDevice.current.orientation in:

viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)

but the orientation always reports unknown.


I've tried subscribing for orientation notifications via:

beginGeneratingDeviceOrientationNotifications()

but, the notifications also never get sent.


I've submitted bug report:

27713359

I'm wondering if the support of landscape (on iPhone) in expanded mode is actually a bug. Try to switch to compact while in landscape and you see what I mean.

I can be in compact and expanded mode in iPhone SE simulator in landscape mode.


And yes, I still get orientation as unknown in Beta 5.

I just ran into this issue, and apparently app extensions has had this issue for a while. This is the workaround I've found:


    override func viewDidLayoutSubviews() {
        if UIScreen.main.bounds.size.width < UIScreen.main.bounds.size.height {
            print("Portrait")
        } else {
            print("Landscape")
        }
    }


Works for me in the meantime, hope they provide a more reliable way to observe for orientation changes though!

UIDevice.current.orientation always reporting unknown in iMessage App.
 
 
Q