Screen orientation - iOS

On iOS, make sure all UIInterfaceOrientationMask values are used for the UISupportedInterfaceOrientations key inside the Info.plist file.

To listen to orientation changes, subscribe to orientationDidChangeNotification. Check the device orientation using UIDevice.current.orientation.

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
private var subscriptions = Set<AnyCancellable>()

override func viewDidLoad() {
    super.viewDidLoad()

    NotificationCenter
        .default
        .publisher(for: UIDevice.orientationDidChangeNotification)
        .sink { [weak self] _ in
            if (UIDevice.current.orientation.isLandscape) {
                // Landscape logic
            } else {
                // Portrait logic
            }
    }
    .store(in: &subscriptions)
}