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
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
Most helpful comment
iam using ionic 3 and this work fine for me