While testing my app I was having trouble with device orientation. Unknown orientation was reported and I could not figure out why. Then I created really simple app for testing
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// UIDevice.current.beginGeneratingDeviceOrientationNotifications()
registerEventListeners()
}
private func registerEventListeners() {
NotificationCenter.default.addObserver(self, selector: #selector(deviceOrientationDidChange), name: UIDevice.orientationDidChangeNotification, object: nil)
}
@objc func deviceOrientationDidChange() {
print("deviceOrientationDidChange \(UIDevice.current.orientation.rawValue)")
}
}
On iPhone 11 Pro it initially prints two lines
deviceOrientationDidChange 1
deviceOrientationDidChange 0
Where first line indicates portrait orientation and second line is some kind of nonsense.
On iPhone 13 Pro it prints correctly only the first line.
Some sort of bug in iOS on some (old) devices?
In code above the .beginGeneratingDeviceOrientationNotifications()
is commented out as it has no effect to anything.