iPad上的Cordova锁定方向失败 [英] Cordova lock orientation on iPad fails
问题描述
我使用cordova 3.5.0-0.2.6(最后一个稳定版本)。
我在锁定iPad设备的方向时遇到问题。
在iPhone上,它正常工作,但在iPad上,方向未锁定。
我想锁定整个应用程序,而不仅仅是页面。 / p>
这是我目前的config.xml:
<?xml version =1.0encoding =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 @ xhref =https://x.com> x< / author>
< content src =index.html?platform = cordova/>
< feature ...>< / feature>
< preference name =permissionsvalue =none/>
< preference name =orientationvalue =portrait/>
< preference name =show-splash-screen-spinnervalue =true/>
< preference name =auto-hide-splash-screenvalue =true/>
< preference name =prerendered-iconvalue =true/>
< preference name =disallowoverscrollvalue =true/>
< preference name =webviewbouncevalue =false/>
< preference name =StatusBarOverlaysWebViewvalue =false/>
< preference name =StatusBarBackgroundColorvalue =#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钩。例如,将它放在 hooks / before_compile
目录中:
var fs = require('fs');
var plist ='./platforms/ios/YourProjectName/YourProjectName-Info.plist';
fs.exists(plist,function(exists){
if(exists){
var p = fs.readFileSync(plist,'utf8');
p = p.replace (
/< key>(UISupportedInterfaceOrientations(\〜ipad)*)< \ / key> [\r\\\
] *< array> [\s\S] *? (?=< \ / array>)/ ig,
< key> $ 1< / key> \\\
\t< array> \\\
\t\t< string& UIInterfaceOrientationLandscapeLeft< / string> \\\
\t\t< string> UIInterfaceOrientationLandscapeRight< / string> \\\
\t
);
fs.writeFileSync(plist,p,utf8 );
}
});
当您为iOS( cordova build ios
),它现在应该自动改变plist。
I'm using cordova 3.5.0-0.2.6 (the last stable version). I'm having problems with locking the orientation for iPad devices. On iPhone it is working properly, but on the iPad the orientation is not locked.
I would like to lock the whole app and not just pages.
This is my current 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>
the generated plist file looks like that:
<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>
A bit of a hack around it, but one way to approach this is via the Cordova hooks. For example, place this in your hooks/before_compile
directory:
var fs = require('fs');
var plist = './platforms/ios/YourProjectName/YourProjectName-Info.plist';
fs.exists(plist, function (exists) {
if (exists) {
var p = fs.readFileSync(plist, 'utf8');
p = p.replace(
/<key>(UISupportedInterfaceOrientations(\~ipad)*)<\/key>[\r\n ]*<array>[\s\S]*?(?=<\/array>)/ig,
"<key>$1</key>\n\t<array>\n\t\t<string>UIInterfaceOrientationLandscapeLeft</string>\n\t\t<string>UIInterfaceOrientationLandscapeRight</string>\n\t"
);
fs.writeFileSync(plist, p, "utf8");
}
});
When you build for iOS (cordova build ios
) it should now alter the plist automatically.
这篇关于iPad上的Cordova锁定方向失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!