Cordova 5 build command is deleting iOS device direction settings

When using Cordova 5.1.1, when executing “cordova build ios”, any device orientation settings previously selected in the XCode project will be deleted, and the orientation setting checkbox is not selected .

Although the “Orientation” configuration preferences may provide a way to force positioning, I need to be able to set different orientation preferences for the iPad and iPhone.

All previous Cordova versions (below 5) respect these settings. Any ideas?

Use XCode 6.3.2.

Edit:

According to @Abhinav Gujjar, fixed an issue that caused cordova to prepare to overwrite the manual changes made to the orientation settings in the .plist. However, AFAIK there is still no way to set different orientations for iPad and iPhone in config.xml Preference, so the answer below is like this.

Update:

I created the plug-in cordova-custom-config, which contains the following hooks, which means it can be in config.xml Define platform-specific custom configuration blocks (such as these orientation settings). So you can use plugins without manually creating the hooks below.

This was introduced in Cordova 5.0.0 CLI – see here .

Meanwhile, I have been using the after_prepare hook as a workaround. Just put the following in /hooks/after_prepare/some_file.js and change the orientation settings as needed:

#!/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) {< br /> 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',< br />'UIInterfaceOrientationLandscapeRight',
'UIInterfaceOrien tationPortrait',
'UIInterfaceOrientationPortraitUpsideDown'
];
var iPadOrientations = [
'UIInterfaceOrientationLandscapeLeft',
'UIInterfaceOrientationLandscapeRight',
'UIInterfaceOrientationPortrait',
'UIInterfaceOrientationPortraitUpsideDown'
];
plist["UISupportedInterfaceOrientations"] = iPhoneOrientations;
plist["UISupportedInterfaceOrientations~ipad"] = iPadOrientations;
}

Note: If you do not have the plist and xml2js node modules, you need to install them.

When using Cordova 5.1.1, when executing “cordova build ios”, the previous Any device orientation settings selected in the XCode project will be deleted, and the orientation setting check box is not checked.

Although the “Orientation” configuration preference may provide a method to force positioning, I need Ability to set different orientation preferences for iPad and iPhone.

All previous Cordova versions (below 5) respect these settings. Any ideas?

Use XCode 6.3.2.

Edit:

According to @Abhinav Gujjar, fixed The problem that caused cordova to prepare to overwrite the manual changes made to the orientation settings in the .plist. However, AFAIK there is still no way to set different orientation preferences for iPad and iPhone in config.xml, so the answer below is that.

Update:

I created the plug-in cordova-custom-config, which contains the following hooks, which means that platform-specific custom configuration blocks (such as these Direction setting). So you can use the plugin without manually creating the hook below.

This was introduced in Cordova 5.0.0 CLI – see here.

At the same time , I have been using the after_prepare hook as a solution. Just put the following in /hooks/after_prepare/some_file.js, and change the orientation setting as needed:

< pre>#!/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’;< br /> });
}
// 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’,
‘UIInterfaceOrientationPortra itUpsideDown’
];
var iPadOrientations = [
‘UIInterfaceOrientationLandscapeLeft’,
‘UIInterfaceOrientationLandscapeRight’,
‘UIInterfaceOrientationPortrait’,
‘UIInterfaceOrientationPortraitUpsideDown’
];
plist[“UISupportedInterfaceOrientations”] = iPhoneOrientations;
plist[“UISupportedInterfaceOrientations~ipad”] = iPadOrientations;
}

Note: If you don’t have a plist yet And xml2js node modules, you need to install them.

Leave a Comment

Your email address will not be published.