Cordova Screen Orientation Ios issue

When I change orientation on Android, it works perfectly, I have a console and it shows portrait-primary and landscape-primary but when I use this in IOS Xcode or real device. When phone is rotated to landscape it shows portrait-primary and it behaves weird and inconsistent.

1 answer

  • answered 2020-03-26 21:37 Muhammad Umair

    This has happened to me as well and its really annoying that same code works on android but not on ios. In ios cordova-screen-orientation takes some time to refresh current orientation and I added a timeout 200ms which works on both platforms.

    Example code:

    this.screenOrientation.onChange().subscribe(() => {
                    setTimeout(() => {
                        if (this.screenOrientation.type.includes('portrait')) {
                            // Portrait
                        } else {
                            // Landscape
                        }
                    }, 200);
                });