Add Entry to iOS .Plist File via Cordova Config.Xml

Add entry to iOS .plist file via Cordova config.xml

I don't think you can do this via straight config.xml modification. At least, I didn't see any mention of this in the docs: http://cordova.apache.org/docs/en/3.3.0/config_ref_index.md.html

I think you have to create a plugin, because they can insert plist entries: http://docs.phonegap.com/en/3.3.0/plugin_ref_spec.md.html#Plugin%20Specification

See the 'config-file element' section. Here's a guess as to what the relevant section of the plugin.xml will look like:

<platform name="ios">
<config-file target="*-Info.plist" parent="CFBundleURLTypes">
<array>
<dict>
<key>GDLibraryMode</key>
<string>GDEnterpriseSimulation</string>
</dict>
</array>
</config-file>
</platform>

Then you can install the plugin: cordova plugin add <your plugin name or file location>

Add fields to info.plist in cordova ios app

After couple of hours of search and few attempts it was actually enough to just add:

<config-file target="*-Info.plist"parent="UIApplicationExitsOnSuspend">
<true/>
</config-file>

(which in my case prevents application from running in the background)

right into config.xml and nest it inside <platform name="ios"> tag as if it was your plugin. And this setting will be added to *-info.plist during cordova build ios without any need to manually install your custom plugin.

Hint: I was firstly mistaken that instead of * in target="*-Info.plist" there has to be your app's title, but as it happens there actually has to be a * symbol and cordova itself will figure out the name of info.plist for you application.

Cordova: Modifying *-Info.plist from plugin.xml

After some further testing and research, I found out how to write the config-file to work properly. Here is the xml

<config-file target="*-Info.plist" parent="UISupportedExternalAccessoryProtocols">
<array>
<string>jp.star-m.starpro</string>
</array>
</config-file>

Here, I changed the parent name from Supported external accessory protocols to UISupportedExternalAccessoryProtocolsand remove the <key> tag and now works as expected.

Ionic v3 Remove Specific Keys from PLIST

These keys are placeholders added by cordova-diagnostic-plugin.

The strings contained within NSLocationAlwaysUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription will only be displayed if you request to use location "Always" at runtime.

Update

To remove those keys from the .plist, you could use cordova-custom-config. First install it:

cordova plugin add cordova-custom-config

Then add <custom-config-file> blocks under <platform name="ios"> to delete the unwanted keys:

<platform name="ios">
<custom-config-file parent="NSLocationAlwaysUsageDescription" target="*-Info.plist" mode="delete"/>
<custom-config-file parent="NSLocationAlwaysAndWhenInUseUsageDescription" target="*-Info.plist" mode="delete"/>

Ionic app not showing various permissions in info plist file despite them being in config.xml

Instead of config-file, you should use edit-config, which allows the use of the merge attribute and allows you to specify more than 1 key

<edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
<string>Explanation</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSPhotoLibraryUsageDescription">
<string>Explanation</string>
</edit-config>


Related Topics



Leave a reply



Submit