Software Archive
Read-only legacy content
公告
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 讨论

Screen orientation plugin is not working.

Ozgur_O_
初学者
1,618 次查看

Hi all.

I'm using Cordova Screen Orientation Plugin for an iOS app.In my app-init.js file the code blocks below supposed to do the job. But it doesn't.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {

    intel.xdk.device.setRotateOrientation("landscape");
    intel.xdk.device.setAutoRotate(false);

    window.screen.lockOrientation('landscape-primary'); 

}

Also this node is added in the config.xml file : <preference name="Orientation" value="landscape" />

mayday.

0 项奖励
7 回复数
PaulF_IntelCorp
1,618 次查看

Please do not use those old intel.xdk functions, they are not getting updated and are obsolete. Please see this FAQ > https://software.intel.com/en-us/xdk/faqs/cordova#app-orientation

0 项奖励
Ozgur_O_
初学者
1,618 次查看

Ok. Thanks for the info.

However I'm still wondering what is the solution.

The last line in the code block is Cordova Screen Orientation Plugin and it's not deprecated. But it doesan't work anyway.

0 项奖励
Anusha_M_Intel1
1,618 次查看

This screen orientation plugin is the solution - https://github.com/gbenvenuti/cordova-plugin-screen-orientation

Many users have had luck with it. Where exactly is it failing?

If you are facing issues with iPad, create a plugin.xml as instructed in the first part of the FAQ. 

0 项奖励
Ozgur_O_
初学者
1,618 次查看

@Anusha Muthiah , Im also trying that solution can be seen in the codes. But the problem is, it's ok when opening the app but when i change the orientation it changes, doesn't prevent its state.

0 项奖励
PaulF_IntelCorp
1,618 次查看

@Ozgur, I just did an experiment with an Android device and the Debug tab, which is an easy way to experiment with the API to make sure you are using it correctly:

For example, I was able to experiment with:

screen.lockOrientation("portrait-primary")
screen.lockOrientation("portrait")
...etc...
cordova.plugins.screenorientation.setOrientation("landscape-primary")
cordova.plugins.screenorientation.setOrientation("landscape-secondary")
...etc...

The docs are not very good, but you can figure out what the APIs are by inspecting the files in the www directory in the github repo and by looking for the "clobbers" and "merges" statements inside the plugin.xml file.

Here's a sample of what part of my console debugging session looked like (this plugin fits part of its API into the window.screen object and the rest into window.cordova.plugins, so I was playing with both objects):

Screen Shot 2016-01-04 at 6.33.26 PM.png

0 项奖励
Ozgur_O_
初学者
1,618 次查看

Hi Paul,

Have you tried to rotate your device and did the orientation change?

I'm using the plugin for an iOS App. Maybe there's a bug for the iOS version...

But there's a difference between your code and mine. I used:

window.screen.lockOrientation('landscape-primary'); 

You used :

cordova.plugins.screenorientation.setOrientation("landscape-primary");

Maybe it makes a difference. 

 

0 项奖励
PaulF_IntelCorp
1,618 次查看

When I used the lockOrientation function my device stayed locked. The setOrientation functions do not lock the screen.

There could be a bug in iOS, check the issues link in the github repo, I recall seeing some recent issues posted there, but I don't recall what they were about.
 

0 项奖励
回复