cordova-plugin-screen-orientation icon indicating copy to clipboard operation
cordova-plugin-screen-orientation copied to clipboard

Ionic 5.x/Screen-Orientation lock does not work on iOS platform

Open cmeuser opened this issue 5 years ago • 15 comments

Bug Report

Problem

Unable to lock the screen orientation on iOS using the latest version of the ionic framework and the plugin.

What is expected to happen?

I'm expecting that both the splash screen and my sign-in page is locked into portrait mode on both iOS and Android.

What does actually happen?

When the app is launched, and the iOS device is in landscape, the splash screen and sign-in page are displayed in landscape.

Information

  • issue observed only on iOS
  • issue observed only on iOS 13.3.1

Command or Code

import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';

constructor( . . . private screenOrientation: ScreenOrientation, . . . ) { . . . this.platform.ready().then(() => { this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT); }); }

Environment, Platform, Device

iOS 13.3.1 iPhone XS Max

Version information

Ionic:

Ionic CLI : 5.4.5 Ionic Framework : @ionic/angular 5.0.7 @angular-devkit/build-angular : 0.803.25 @angular-devkit/schematics : 8.3.25 @angular/cli : 8.3.25 @ionic/angular-toolkit : 2.1.2

Cordova:

Cordova CLI : 9.0.0 ([email protected]) Cordova Platforms : ios 5.1.1 Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 11 other plugins)

Utility:

cordova-res : not installed native-run : 0.3.0

System:

Android SDK Tools : 26.1.1 (/Users/meusercx/Library/Android/sdk) ios-deploy : 1.9.2 ios-sim : 8.0.2 NodeJS : v10.15.1 (/usr/local/bin/node) npm : 6.14.4 OS : macOS Catalina Xcode : Xcode 11.3.1 Build version 11C504


package.json... "@ionic-native/screen-orientation": "^5.23.0", "cordova-plugin-screen-orientation": "3.0.2",

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

cmeuser avatar Apr 01 '20 14:04 cmeuser

Is your plugin actually installed?

Cordova CLI : 9.0.0 ([email protected]) Cordova Platforms : none Cordova Plugins : no whitelisted plugins (0 plugins total)

Please also test the issue without Ionic and use the window.screen object instead.

timbru31 avatar Apr 01 '20 14:04 timbru31

Besides that, affected iOS devices and versions are missing in your issue.

timbru31 avatar Apr 01 '20 14:04 timbru31

I've updated the Environment, Platform, and Device section of the bug report as well as the Version Information. I just ran the same app as reported, which uses Ionic 5, on my iPhone 6 Plus/iOS 12.4.6 and did NOT observe the issue. Additionally, I ran the production version of the app, which is built using Ionic 4, on my iPhone XS Max/iOS 13.3.1 and observed the same issue reported here but did NOT observe the issue on my iPhone 6 Plus/iOS 12.4.6. This appears to be an issue related to iOS 13.x.

cmeuser avatar Apr 01 '20 16:04 cmeuser

I've seen a similar problem...

bfan1256 avatar Apr 19 '20 16:04 bfan1256

I'm experiencing the same problem.

chilupa avatar Apr 27 '20 08:04 chilupa

Same here

Cordova 9, ios 13.4, Xcode 11.4

In devtools, screen.orientation is undefined

pandaiolo avatar May 12 '20 21:05 pandaiolo

Does not work here either:

Xcode 11.4.1 Ipad Pro - IOS 13.4.1 (actual device) "@ionic/angular": "^4.11.5", "@capacitor/core": "^1.5.1", "@capacitor/ios": "^1.5.1", "@ionic-native/screen-orientation": "^5.26.0", "cordova-plugin-screen-orientation": "^3.0.2"

Although, this same configuration works fine for my iPhone 8+ running IOS 13.4.1. I used window.screen and the Ionic way as well.

Both ways lead to -> Native Cordova -> CDVOrientation screenOrientation INVALID ["options": [3, portrait]]

bcrigler avatar May 28 '20 20:05 bcrigler

Please see https://github.com/apache/cordova-plugin-screen-orientation/issues/59 - could it be that you have split screen enabled?

timbru31 avatar May 28 '20 21:05 timbru31

From my knowledge and reading of the affected devices this seems a lot like #59, since only iPads and iPhone Max devices seem affected.

timbru31 avatar May 28 '20 21:05 timbru31

So for my issue... @timbru31 you pointed me in the correct direction. My app does require full screen and I did not have that set. Once I set that option now the screen orientation locks as expected. I piggybacked off this thread though, and that does not seem to be the case of the original poster. Just to add some info. In the iPhone 11 Pro Max simulator running IOS 13.4.1 I do not see this issue BUT... I'm using Ionic 4.x so 5.x could be different.

bcrigler avatar May 28 '20 21:05 bcrigler

I had the same problem with the orientation lock working on iphones but not ipad. To fix it so I could lock in portrait mode only on both device types:

Edit the generate ios project's Info.plist file and under the keys UISupportedInterfaceOrientations & UISupportedInterfaceOrientations~ipad I removed all but the option for portrait ending up with

<key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortrait</string> </array> <key>UISupportedInterfaceOrientations~ipad</key> <array> <string>UIInterfaceOrientationPortrait</string> </array>

ahollandusc avatar Jun 03 '20 06:06 ahollandusc

i had the same issue, it seems the plugin is still not loaded at the time the app component already start to initialize, my current workaround solution is to add below code to delay the app component loading process:

if(this.platform.is('ios'){ const startTime = new Date().getTime() + parseInt('3000', 10); while(new Date().getTime() < startTime) {}; }

call the screenOrientation operations here..

gitlizm1981 avatar Jul 29 '20 09:07 gitlizm1981

Came across this post while looking for a solution the same problem..

by looking into the logs, I realized I missed to call:

ionic cordova plugin add cordova-plugin-screen-orientation

wzr1337 avatar Oct 05 '20 10:10 wzr1337

Came across this post while looking for a solution the same problem..

by looking into the logs, I realized I missed to call:

ionic cordova plugin add cordova-plugin-screen-orientation

This only applies to pre-capacitor versions of Ionic

ammarhaiderbjss avatar Jan 12 '21 16:01 ammarhaiderbjss

i had the same issue, it seems the plugin is still not loaded at the time the app component already start to initialize, my current workaround solution is to add below code to delay the app component loading process:

if(this.platform.is('ios'){ const startTime = new Date().getTime() + parseInt('3000', 10); while(new Date().getTime() < startTime) {}; }

call the screenOrientation operations here..

Didn't work here. Is there another solution?

bastifix avatar May 06 '21 14:05 bastifix