Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
cordova-common@2.2.3
-
None
-
Cordova CLI, ios
Description
I have added following edit-config to my config.xml:
<edit-config file="*-Info.plist" mode="overwrite" target="UISupportedInterfaceOrientations"> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortraitUpsideDown</string> </array> </edit-config> <edit-config file="*-Info.plist" mode="overwrite" target="UISupportedInterfaceOrientations~ipad"> <array> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> </edit-config>
But, the ionic cordova prepare throws exception doc.find is not a function. I have made the following change to utils files(/usr/local/lib/node_modules/cordova/node_modules/cordova-common/src/util) in my local to fix this issue.
// File ConfigFile.js ConfigFile.prototype.graft_child = function ConfigFile_graft_child (selector, xml_child) { var self = this; var filepath = self.filepath; var result; if (self.type === 'xml') { var xml_to_graft = [modules.et.XML(xml_child.xml)]; switch (xml_child.mode) { case 'merge': result = modules.xml_helpers.graftXMLMerge(self.data, xml_to_graft, selector, xml_child); break; case 'overwrite': result = modules.xml_helpers.graftXMLOverwrite(self.data, xml_to_graft, selector, xml_child); break; case 'remove': result = modules.xml_helpers.pruneXMLRemove(self.data, selector, xml_to_graft); break; default: result = modules.xml_helpers.graftXML(self.data, xml_to_graft, selector, xml_child.after); } if (!result) { throw new Error('Unable to graft xml at selector "' + selector + '" from "' + filepath + '" during config install'); } } else { // plist file. Passed mode from here result = modules.plist_helpers.graftPLIST(self.data, xml_child.xml, selector, xml_child.mode); if (!result) { throw new Error('Unable to graft plist "' + filepath + '" during config install'); } } self.is_changed = true; };
// File: xml-helper.js resolveParent: function (doc, selector) { var parent, tagName, subSelector; // handle absolute selector (which elementtree doesn't like) if (ROOT.test(selector)) { tagName = selector.match(ROOT)[1]; // test for wildcard "any-tag" root selector if (tagName === '*' || tagName === doc._root.tag) { parent = doc._root; // could be an absolute path, but not selecting the root if (ABSOLUTE.test(selector)) { subSelector = selector.match(ABSOLUTE)[2]; parent = parent.find(subSelector); } } else { return false; } } else { // here is the issue for exception "doc.finf is not a function" parent = Array.isArray(doc) ? doc.find(selector) : doc[selector]; } return parent; }
// File: plist-helper.js function graftPLIST (doc, xml, selector, mode) { var obj = plist.parse('<plist>' + xml + '</plist>'); var node = doc[selector]; if (node && Array.isArray(node) && Array.isArray(obj)) { // node = node.concat(obj); // addressed overwrite mode here (mode == 'overwrite') ? (node = obj) : (node = node.concat(obj)); for (var i = 0; i < node.length; i++) { for (var j = i + 1; j < node.length; ++j) { if (nodeEqual(node[i], node[j])) { node.splice(j--, 1); } } } doc[selector] = node; } else { // plist uses objects for <dict>. If we have two dicts we merge them instead of // overriding the old one. See CB-6472 if (node && __.isObject(node) && __.isObject(obj) && !__.isDate(node) && !__.isDate(obj)) { // arrays checked above __.extend(obj, node); } doc[selector] = obj; } return true; }