Hello , i search all around google and this forum about how to luck the screen orientation , and anything a found cant solve my problem , when i use the Screen Orientation native plugin of crodove
(Link to how : https://ionicframework.com/docs/v2/native/screen-orientation/)
i used the commands below in the platform.ready().then(()) section and nothig work
window.screen.lockOrientation('portrait'); - window.screen.lockOrientation is not a function
or
ScreenOrientation.lockOrientation('portrait'); -Cannot read property 'apply' of undefined TypeError: Cannot read property 'apply' of undefined at callCordovaPlugin
or
screen.lockOrientation('portrait'); - Property 'lockOrientation' does not exist on type 'Screen'.
this all app.component.ts page :
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { ScreenOrientation } from 'ionic-native';
import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage = HomePage;
constructor(platform: Platform) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
ScreenOrientation.lockOrientation('portrait');
});
}
}
Hey , thank you for your reply but i cant understand how its works for you , i use your all code page in my project , upload to the ionic view addon and from my iphone the screen orientation didn’t lock when i press the button.
I think the problem is Ionic View.
Maybe the app doesn’t support lock orientation.
I would suggest to build and test the app on a device, without using Ionic view.
Hi, I used your code, but got an error in the console running on android (and the screen is not locked) :
screen should be locked to prtrait
main.js:17 EXCEPTION: Uncaught (in promise): TypeError: Cannot read property ‘apply’ of undefined
TypeError: Cannot read property ‘apply’ of undefined
at r (file:///android_asset/www/build/main.js:1:8881)
at Function. (file:///android_asset/www/build/main.js:1:14142)
at Function.value [as lockOrientation] (file:///android_asset/www/build/main.js:1:11860)
at file:///android_asset/www/build/main.js:18:25520
at t.invoke (file:///android_asset/www/build/polyfills.js:3:9655)
at Object.inner.inner.fork.onInvoke (file:///android_asset/www/build/main.js:3:20574)
at t.invoke (file:///android_asset/www/build/polyfills.js:3:9606)
at e.run (file:///android_asset/www/build/polyfills.js:3:7019)
at file:///android_asset/www/build/polyfills.js:3:4661
at t.invokeTask (file:///android_asset/www/build/polyfills.js:3:10284)
at Object.inner.inner.fork.onInvokeTask (file:///android_asset/www/build/main.js:3:20474)
at t.invokeTask (file:///android_asset/www/build/polyfills.js:3:10220)
at e.runTask (file:///android_asset/www/build/polyfills.js:3:7637)
at i (file:///android_asset/www/build/polyfills.js:3:3707)t.handleError @ main.js:17
Here is my code placed in the constructor of a page:
this.platform.ready().then(() => {
this.isCordova = this.platform.is(“cordova”);
this.isAndroid = this.platform.is(“android”);
if (this.isCordova) {
console.log(“screen should be locked to prtrait”);
ScreenOrientation.lockOrientation(‘portrait’);
}
My ionic info
Cordova 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.1.3
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.4
Node Version: v7.8.0
Xcode version: Not installed