Creé una aplicación iOS (iPhone) usando Cordova y quiero solo permitir las siguientes orientaciones:
Esto también significa que "al revés" no debería permitirse :
Sé que puedo configurar esto en Xcode, pero cada vez que empiezo una nueva compilation de Cordova, esta configuration se sobrescribe.
Así que revisé los documentos de Cordova y encontré esto: http://cordova.apache.org/docs/en/5.1.1/config_ref_index.md.html#The%20config.xml%20File
Dice que puedo establecer la orientación en config.xml así:
<preference name="Orientation" value="landscape" />
Pero no veo cómo puedo establecer una configuration granular más fina como describí anteriormente. ¿Cómo se puede hacer esto?
Nota: estoy en Cordova 5.1.1
Puedes usar config.xml '
<platform name="ios"> <preference name="Orientation" value="all" /> </platform>
junto con callback shouldRotateToOrientation(degrees)
como se indica en los documentos así:
onDeviceReady: function() { app.receivedEvent('deviceready'); window.shouldRotateToOrientation = function(degrees) { return degrees !== 180; }; },
Puede utilizar un gancho after_prepare que aplicará la configuration después de que se cordova prepare
el cordova prepare
y, por lo tanto, evitará que se sobreescriban en cada cordova build
. Coloque el siguiente código en <your_project>/hooks/after_prepare/some_file.js
:
#!/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' ]; var iPadOrientations = [ 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight', 'UIInterfaceOrientationPortrait' ]; plist["UISupportedInterfaceOrientations"] = iPhoneOrientations; plist["UISupportedInterfaceOrientations~ipad"] = iPadOrientations; }
Nota: necesitará instalar los modules de nodo plist y xml2js si aún no los tiene.