Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 3 - Screen Orientation Lock not working

My requirement is to have the app fixed only to portrait mode on phones and only to landscape mode on tabs, starting with the splashscreen. Tried with the Screen Orientation plugin available on ionic native but did not work for me.

Things I have tried:

On app.component.ts:

constructor(..., private screenOrientation: ScreenOrientation) {
    platform.ready().then(() => {

        this.screenOrientation.lock('landscape');
        ScreenOrientation.lockOrientation('landscape');
        screen.msLockOrientation('landscape');
    this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);

I have tried all of the above lines on home.ts too but they didn't work. When I set:

console.log(this.screenOrientation.type); 

This will print out the screen orientation correctly in logs. Whenever I set the subscribe method, that too works and alerts me whenever the screen orientation changes, which means that all the import statements are working perfectly and that I am able to access the plugin methods correctly. I am able to replicate this issue on both Android and iOS. Any help would be greatly appreciated.

Platform/library/dependency details:

"@angular/common": "4.1.3",

"ionic-angular": "3.6.0",

"ionic": "3.7.0"

like image 544
Mohammed Azhar Avatar asked Aug 10 '17 18:08

Mohammed Azhar


1 Answers

In your config.xml you can try to add this line to make your orientation to lock on landscape mode.

<preference name="orientation" value="landscape" />
like image 147
Jakegarbo Avatar answered Nov 01 '22 18:11

Jakegarbo