iPad 上的 Cordova 锁定方向失败

2024-05-24

我正在使用 cordova 3.5.0-0.2.6 (最后一个稳定版本)。 我在锁定 iPad 设备的方向时遇到问题。 在 iPhone 上它可以正常工作,但在 iPad 上方向未锁定。

我想锁定整个应用程序而不仅仅是页面。

这是我当前的 config.xml:

<?xml version="1.0" encoding="utf-8"?>
<widget id="com.domain"
        version="version"
        xmlns="http://www.w3.org/ns/widgets">
    <name>xxx</name>

    <description>Lorem ipsum</description>

    <access origin="*"/>

    <author email="x@x" href="https://x.com">x</author>

    <content src="index.html?platform=cordova"/>

    <feature ...></feature>

    <preference name="permissions" value="none"/>
    <preference name="orientation" value="portrait"/>
    <preference name="show-splash-screen-spinner" value="true"/>
    <preference name="auto-hide-splash-screen" value="true"/>
    <preference name="prerendered-icon" value="true"/>
    <preference name="disallowoverscroll" value="true"/>
    <preference name="webviewbounce" value="false"/>

    <preference name="StatusBarOverlaysWebView" value="false"/>
    <preference name="StatusBarBackgroundColor" value="#000000"/>
</widget>

生成的 plist 文件如下所示:

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations¨ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

我尝试了很多解决这个错误的方法,但大多数都失败了。幸运的是,我找到了一个 Cordova 插件,它可以让你通过 JavaScript 成功锁定屏幕方向。也可以在 iPad 上工作。

https://github.com/yoik/cordova-yoik-screenorientation https://github.com/yoik/cordova-yoik-screenorientation

  1. 添加插件:cordova plugin add net.yoik.cordova.plugins.screenorientation
  2. 使用锁定屏幕screen.lockOrientation('portrait-primary')在 JavaScript 中。请务必在文档结束后调用此函数deviceready已解雇。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iPad 上的 Cordova 锁定方向失败 的相关文章

随机推荐