UIDevice orientation not preserved when changing the root view controller.

Originator:westono
Number:rdar://42836524 Date Originated:August 1 2018
Status:Open Resolved:
Product:UIKit Product Version:
Classification:Bug Reproducible:Always
 
Area:
UIKit

Summary:
UIDevice orientation not preserved when changing the root view controller.

Steps to Reproduce:
-- In a test case --
* See attached project with the following unit test:
// Change the device orientation.
XCUIDevice.sharedDevice.orientation = UIDeviceOrientationLandscapeLeft;
XCTAssertEqual(UIDevice.currentDevice.orientation, UIDeviceOrientationLandscapeLeft);
XCTAssertEqual(XCUIDevice.sharedDevice.orientation, UIDeviceOrientationLandscapeLeft);
// Change the root view controller.
UIApplication.sharedApplication.keyWindow.rootViewController = [[UIViewController alloc] init];
// XCUIDevice orientation is preserved.
XCTAssertEqual(XCUIDevice.sharedDevice.orientation, UIDeviceOrientationLandscapeLeft);
// UIDevice orientation is NOT preserved (the following assertion fails).
XCTAssertEqual(UIDevice.currentDevice.orientation, UIDeviceOrientationLandscapeLeft);

-- In the debugger --
1) Pause program execution to enter the debugger.
2) Run the following lldb commands:
(lldb) po UIDevice.currentDevice.orientation
UIDeviceOrientationPortrait
(lldb) expr UIApplication.sharedApplication.keyWindow.rootViewController = [UIViewController new];
(UIViewController *) $3 = 0x00007fd29dc06c40
(lldb) po UIDevice.currentDevice.orientation
UIDeviceOrientationUnknown

Expected Results:
UIDevice.currentDevice.orientation should have the same orientation before and after the root view controller is changed.

Actual Results:
UIDevice.currentDevice.orientation returns UIDeviceOrientationUnknown after the root view controller is changed.

Version/Build:
Xcode v9.4.1 - v10.0 beta 5 (I didn't try earlier than v9.4.1)
iOS SDK 10.0-12 (I didn't try earlier than SDK 10)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!