Arrays in plist files can not be adjusted with edit-config
See original GitHub issueBug Report
Problem
What is expected to happen?
When you want to have device-specific orientation options, like only portrait on phone, but allow landscape on iPad, you’d want to use edit-config
to adjust your .plist
accordingly.
What does actually happen?
When you use edit-config
to make adjustments not covered by the preference
for orientation, they will not be persisted to the .plist
for your iOS project.
Information
Possibly related to https://github.com/apache/cordova-common/commit/9c6cda3db766c3daa87e8e4f8cc65e818a9e6dfc (https://issues.apache.org/jira/browse/CB-13496)
The edit-config
directives would be:
<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>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</edit-config>
The result will be (regardless of the configuration details above):
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Only using <preference name="Orientation" value="foo" />
has an effect on the issue.
When you change the key UISupportedInterfaceOrientations
to any other string, it will be persisted to the .plist
correctly.
When you remove the UISupportedInterfaceOrientations
directives from the template .plist
, the final result is as expected.
Command or Code
oliver@oliver-home MINGW64 ~
$ cordova create ios-orientation-bug
$ cd ios-orientation-bug/
$ cordova platform add ios
Then add the above edit-config
directives to the newly created config.xml
and cordova prepare
.
Environment, Platform, Device
Reproduced in builds on OSX and Windows.
Version information
9.0.0 (cordova-lib@9.0.1) cordova-ios@5.0.1
Checklist
- I searched for existing GitHub issues
- I updated all Cordova tooling to most recent version
- I included all the necessary information above
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (4 by maintainers)
Top GitHub Comments
Thanks for this detailed issue report. I can reproduce the behavior described by you and after some code reading, I unfortunately have to confirm that what you want to do is indeed not possible with
edit-config
orconfig-file
tags at the moment. Below I will provide more details on my findings and a possible workaround.First off,
edit-config
is for editing attributes only. To quote the docs (emphasis mine):So what you are trying to do above is not supposed to work. Deletion of tags is not supported using Cordova’s built-in config editing mechanism. Neither for plist nor for any other XML files.
The reason I am making this distinction here, is that plist files are handled separately from other XML files. If you look at the linked code, you will realize that the
mode
of the config change is completely disregarded for plist files. In fact, all changes to a plist file are handled by this code which only does merges. Either of objects or of arrays. That explains the results you are seeing.This special treatment of plist files seems to make sense given the fact that, due to their specific structure, we could do very little of use with them if we would apply the default rules for other XML files. However, I could not find this special treatment to be documented anywhere (did I miss it?). Furthermore I clearly see the limitations of the current editing capabilities – for plist files as well as for other XML files.
As a workaround, the following
after_prepare
hook should be able to do what you want:So what do we take away from this issue? My suggestions would be:
edit-config
/mode
with plist filesAny additions?
PS: I don’t think any of the issues linked from here are actually related to this issue.
.build/overwritePlistContent.js
:In
config.xml
:<hook src=".build/overwritePlistContent.js" type="after_prepare" />