简体   繁体   English

你如何强制使用cordova-cli构建移动应用程序的横向?

[英]How do you force a landscape orientation for mobile apps built with cordova-cli?

I'm using cordova cli to build my app. 我正在使用cordova cli构建我的应用程序。 I want to target both android and ios (maybe more). 我想针对android和ios(可能更多)。

As I want this to be true for all platforms, I was hoping I could simply define this as a preference in the config.xml like this: 正如我希望所有平台都适用,我希望我可以简单地在config.xml中将其定义为首选项,如下所示:

<preference name="orientation" value="landscape" />

because this is apparently how it works in the phonegap build https://build.phonegap.com/docs/config-xml 因为这显然是它在phonegap构建中的工作原理 https://build.phonegap.com/docs/config-xml

I assume the features supported in config.xml by phonegap build are different to those by cordova-cli? 我假设phonegap build中config.xml支持的功能与cordova-cli不同?

I know I can force it in the android app by inserting android:screenOrientation="landscape" into my AndroidManifest.xml, but that's no good because it will be over-written the next time I perform a cordova build . 我知道我可以通过在我的AndroidManifest.xml中插入android:screenOrientation="landscape"来强制它在Android应用程序中,但这并不好,因为它将在下次执行cordova build时被覆盖。

Any suggestions? 有什么建议?

This is no longer the case. 这已不再是这种情况。 The "orientation" preference in the config.xml is now honored by the cordova cli starting from version 3.4 config.xml中的“orientation”首选项现在由版本3.4开始的cordova cli授予

This is the corresponding issue : https://issues.apache.org/jira/browse/CB-5634 这是相应的问题: https//issues.apache.org/jira/browse/CB-5634

Simply put, it's not possible to set the orientation using a preference element in the www/config.xml . 简单地说,不可能使用www/config.xmlpreference元素设置方向。 After inspecting the cordova-cli code it appears that only the version and entry class package are updated in the AndroidManifest.xml . 检查cordova-cli代码后 ,似乎只在AndroidManifest.xml中更新了版本和入口类包。

For a list of supported preferences see the Cordova Docs . 有关支持的首选项列表,请参阅Cordova文档

Added configurations to the AndroidManifest.xml file should not be lost on cordova build , unless the config option is pulled from somewhere else (ie version). 除非从其他地方(即版本)提取配置选项,否则不应在cordova build丢失对AndroidManifest.xml文件的添加配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM