Ionic-native: Lock orientation not working in latest

Created on 6 Apr 2017  路  12Comments  路  Source: ionic-team/ionic-native

After upgrading from ionic-native (v2) to @ionic-native/screen-orientation (v3.4.4) I get the following error when trying to lock screen orientation with the following code:
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);

Runtime error:
Uncaught (in promise): NotSupportedError: lockOrientation() is not available on this device.

$ ionic info

Your system information:

 ordova CLI: 6.5.0
Ionic Framework Version: 2.3.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 8.1
Node Version: v6.9.2
Xcode version: Not installed

I have only tested on Genymotion Android simulator, not a real device.

I have tried:
ionic platform rm android
ionic platform add android

Most helpful comment

iam using ionic 3 and this work fine for me

if(this.platform.is('cordova')){
  this.platform.ready().then(()=>{
    this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
  })
}

All 12 comments

Upgrading cordova-plugin-screen-orientation to 2.0.0 resolves the problem.

I have the same problem on Android using 2.0.1

Same on 2.0.2.

Experiencing this with 2.0.2 as well.

I am experiencing the same issue with the following local packages

ionic/app-scripts : 3.1.6
Cordova Platforms : android 6.3.0
Ionic Framework : ionic-angular 3.9.2

I found the issue was because I tried to use the plugin before deviceready has fired. Try to wrap your method calls with platform.ready()

Also using the if statement if (platform.is('cordova')) could help to only use the lock on mobile devices.

have the same issue here even with platform.ready()
"@ionic-native/screen-orientation": {
"version": "4.5.3",

in my experiencing It works only if you use it in a service and if you call it inside platform.ready()

iam using ionic 3 and this work fine for me

if(this.platform.is('cordova')){
  this.platform.ready().then(()=>{
    this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
  })
}

thanks @TheSniper102 your solution works

confirm that you have installed cordova-plugin-screen-orientation.

ionic cordova plugin add cordova-plugin-screen-orientation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

mateo666 picture mateo666  路  3Comments

ajcrites picture ajcrites  路  3Comments

danbucholtz picture danbucholtz  路  3Comments

GunaSekhar1 picture GunaSekhar1  路  4Comments