Cordova 5 build命令正在删除iOS设备方向设置 [英] Cordova 5 build command is deleting iOS device orientation settings

查看:149
本文介绍了Cordova 5 build命令正在删除iOS设备方向设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Cordova 5.1.1,当执行cordova build ios时,将删除先前在XCode项目中选择的任何设备方向设置,而不选择方向设置复选框。

With Cordova 5.1.1, when executing "cordova build ios", any device orientation settings previously selected in the XCode project are deleted leaving the orientation settings checkboxes unselected.

虽然orientation配置首选项可能提供强制方向的方法,我需要能够为iPad和iPhone设置不同的方向首选项。

While the "orientation" config preference may provide a means of forcing orientation, I need to be able to set different orientation preferences for the iPad and iPhone.

所有以前的Cordova版本(低于5)都遵守这些设置。任何想法?

All previous Cordova versions (below 5) respected those settings. Any ideas?

使用XCode 6.3.2。

Using XCode 6.3.2.

推荐答案

strong> EDIT:

根据 @Abhinav Gujjar 导致 cordova准备覆盖对.plist中的方向设置所做的手动更改的问题已修复。但是,AFAIK仍然没有办法在config.xml中为iPad和iPhone设置不同的方向首选项,因此下面的答案是正确的。

According to @Abhinav Gujjar the issue causing cordova prepare to overwrite manual changes made to orientation settings in the .plist has been fixed. However, AFAIK there's still no way to set different orientation preferences for iPad vs iPhone in the config.xml, so the answer below stands.

UPDATE

我创建了插件 cordova- custom-config ,它包含了下面的钩子,意味着平台特定的自定义配置块(例如这些方向设置)可以在config.xml中定义。所以你可以使用插件,而不需要手动创建下面的钩子。

I created the plugin cordova-custom-config, which wraps up the hook below and means platform-specific custom config blocks (such as these orientation settings) can be defined in config.xml. So you can use the plugin rather than need to manually create the hook below.

这是在Cordova 5.0中引入的。 0 CLI - 请参阅此处

This was introduced in the Cordova 5.0.0 CLI - see here.

在此期间,我一直使用一个after_prepare钩子作为解决方法。只需在< your_project> /hooks/after_prepare/some_file.js 中放置以下内容,并根据需要更改方向设置:

In the meantime, I've been using an after_prepare hook as a workaround. Just place the following in <your_project>/hooks/after_prepare/some_file.js and change the orientation settings as appropriate:

#!/usr/bin/env node

// Set support for all orienations in iOS .plist - workaround for this cordova bug: https://issues.apache.org/jira/browse/CB-8953
var platforms = process.env.CORDOVA_PLATFORMS.split(',');
platforms.forEach(function(p) {
    if (p == "ios") {
        var fs = require('fs'),
            plist = require('plist'),
            xmlParser = new require('xml2js').Parser(),
            plistPath = '',
            configPath = 'config.xml';
        // Construct plist path.
        if (fs.existsSync(configPath)) {
            var configContent = fs.readFileSync(configPath);
            // Callback is synchronous.
            xmlParser.parseString(configContent, function (err, result) {
                var name = result.widget.name;
                plistPath = 'platforms/ios/' + name + '/' + name + '-Info.plist';
            });
        }
        // Change plist and write.
        if (fs.existsSync(plistPath)) {
            var pl = plist.parseFileSync(plistPath);
            configure(pl);
            fs.writeFileSync(plistPath, plist.build(pl).toString());
        }
        process.exit();
    }
});
function configure(plist) {
    var iPhoneOrientations = [
        'UIInterfaceOrientationLandscapeLeft',
        'UIInterfaceOrientationLandscapeRight',
        'UIInterfaceOrientationPortrait',
        'UIInterfaceOrientationPortraitUpsideDown'
    ];
    var iPadOrientations = [
            'UIInterfaceOrientationLandscapeLeft',
            'UIInterfaceOrientationLandscapeRight',
            'UIInterfaceOrientationPortrait',
            'UIInterfaceOrientationPortraitUpsideDown'
    ];
    plist["UISupportedInterfaceOrientations"] = iPhoneOrientations;
    plist["UISupportedInterfaceOrientations~ipad"] = iPadOrientations;
}



注意:如果你需要安装plist和xml2js节点模块尚未有他们。

Note: you'll need to install the plist and xml2js node modules if you don't already have them.

这篇关于Cordova 5 build命令正在删除iOS设备方向设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆