Cordova 5 build命令是删除iOS设备方向设置
使用Cordova 5.1.1时,执行“cordova build ios”时,先前在XCode项目中select的任何设备方向设置都将被删除,而未选中方向设置checkbox。
虽然“方向”configuration偏好可以提供强制定位的手段,但我需要能够为iPad和iPhone设置不同的方向偏好。
所有以前的cordova版本(低于5)尊重这些设置。 有任何想法吗?
使用XCode 6.3.2。
编辑:
根据@Abhinav Gujjar ,导致cordova prepare
盖写.plist中对方向设置的手动更改的问题已得到解决。 但是,AFAIK仍然没有办法在config.xml中为iPad和iPhone设置不同的方向偏好,所以下面的答案就是这样。
更新 :
我创build了插件cordova-custom-config ,它包装了下面的钩子,并且意味着可以在config.xml中定义特定于平台的自定义configuration块(例如这些方向设置)。 所以你可以使用插件,而不需要手动创build下面的钩子。
这是在Cordova 5.0.0 CLI中引入的 – 请参阅此处 。
在此期间,我一直在使用after_prepare钩子作为解决方法。 只需将以下内容放在<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', 'UIInterfaceOrientationPortraitUpsideDown' ]; var iPadOrientations = [ 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight', 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown' ]; plist["UISupportedInterfaceOrientations"] = iPhoneOrientations; plist["UISupportedInterfaceOrientations~ipad"] = iPadOrientations; }
注意:如果您尚未安装plist和xml2js节点模块,则需要安装它们。
如果你想,你可以在JS方面编程。
对于iOS,可以通过在窗口上定义一个JavaScriptcallback来以编程方式控制方向
/** // @param {Number} degree - UIInterfaceOrientationPortrait: 0, // UIInterfaceOrientationLandscapeRight: 90, // UIInterfaceOrientationLandscapeLeft: -90, // UIInterfaceOrientationPortraitUpsideDown: 180 * @returns {Boolean} Indicating if rotation should be allowed. */ function shouldRotateToOrientation(degrees) { return true; }
在您的config.xml
文件中设置允许的方向
<platform name="ios"> <preference name="Orientation" value="all" /> </platform>
并添加shouldRotateToOrientation(degrees)
onDeviceReady: function() { app.receivedEvent('deviceready'); window.shouldRotateToOrientation = function(degrees) { //if device an iPad ? if ( navigator.userAgent.match(/iPad/i) ) { return true; } //else if device an iPhone ? else if (navigator.userAgent.match(/iPhone/i)) { if (degrees == 0) { //orientation is portrait return true; } return false; //refuse all other orientations for iPhone } return true; }; }
这个问题已经解决了,你现在可以在config.xml中指定方向为'all'
<platform name="ios"> <preference name="Orientation" value="all" /> </platform>
文件
- 技术行业的开发人员是否认为混合移动应用程序通常被认为比Native应用程序差?
- cordova3.1.0:找不到插件或不是CDVPlugin
- KineticJS图像标注工具跨设备
- VS2013 Cordova iOS Remotebuild错误无法POST /build/tasks?command=build&vcordova=4.3.1&cfg=debug
- 为什么你需要2个Javascript文件用于跨平台Cordova插件?
- iPhone上的PhoneGap不会加载外部脚本
- 离子2 / cordova从Documents目录下读取图像iOS
- 离子2 Facebook的login – '应用程序不安装'和'没有login'&'给定的URL是不允许的'错误
- 当静止时,Apache Cordova geolocation.watchPosition()在iOS上超时