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

后端 未结 15 1330
日久生厌
日久生厌 2020-11-28 21:41

I am new to the Cordova CLI.

I need to perform the following steps programmatically via Cordova.

  1. In the project .plist add a new row
  2. Enter th
相关标签:
15条回答
  • 2020-11-28 22:08

    Yes, it is possible!

    I am using Cordova 9.0.0 (cordova-lib@9.0.1).

    For example this is the configuration file that I used to insert new string value into Info.plist :

    <platform name="ios">
        <edit-config file="*-Info.plist" mode="merge" target="NSMicrophoneUsageDescription">
            <string>My awesome app wish to hear your awesome voice through Microphone. Not for fancy stuff, just want to hear you.</string>
        </edit-config>
        <edit-config file="*-Info.plist" mode="merge" target="---Key configuration---">
            <string>---string value---</string>
        </edit-config>
    </platform>
    

    After that, don't forget to rebuild your staging file by running this two command in your terminal :

    cordova platform rm ios
    cordova platform add ios
    

    To confirm the change, you can check the newly generated .plist file by opening them with xCode.

    -Info.plist file located at :

    ./platform/ios/[your app name]/[your app name]-Info.plist
    
    0 讨论(0)
  • 2020-11-28 22:08

    If you are trying to modify a .plist in a native iOS plugin with a <config-file> tag in your plugin.xml, here is what you need to do:

    1. Make sure your .plist is xml, not binary! You can use plutil to convert a binary .plist into xml, and commit it to version control.

      plutil -convert xml1 Info.plist

    2. The instructions for <config-file> indicate that target= is relative to the generated xcode project at platforms/ios/<project>/, but I found that I needed to prepend a wildcard character to my path to get it to work:

      target="*/Resources/MyResources.bundle/Info.plist"

    3. If you want to add a key at the top level of the .plist, you need to set parent equal to the key name, and then nest a <string> tag with the value. Using an <array> or <dict> as any examples show will cause these keys to be nested under parent.

    Here is a complete example that works for me for adding multiple top level properties:

    <platform name="ios">
        <config-file target="*/Resources/MyResources.bundle/Info.plist" parent="MyDistribution">
            <string>Cordova</string>
        </config-file>
        <config-file target="*/Resources/MyResources.bundle/Info.plist" parent="MyVersion">
            <string>3.2.0</string>
        </config-file>
    </platform>
    
    0 讨论(0)
  • 2020-11-28 22:09

    You can set the display name in app's plist by directly editing the ios.json in the plugins directory.

    Adding the following to the config_munge.files section of the ios.json file will do the trick and it will be maintained even when using the CLI.

    "*-Info.plist": {
    
        "parents": {
            "CFBundleDisplayName": [
                {
                    "xml": "<string>RevMob Ads Cordova Plugin Demo</string>",
                    "count": 1
                }
            ]
        }
    }
    

    Here's a complete example

    0 讨论(0)
  • 2020-11-28 22:09

    you just need following steps 1.

    Go to Project navigator Select the target Click on info from tab option other option are build setting build phase you will see key type value When you point on any key name you will find + and - sign click on the + sign write Key: GDLibraryMode in key section Type:Stringin tyoe section Value:GDEnterpriseSimulation in value section

    0 讨论(0)
  • 2020-11-28 22:12

    I prefer the after_prepare hook for bigger projects or if you have multiple plugins using the same permissions. But you can always go the simple way:

    simply: - remove the plugin that requires the desired permission - add it again with --save - in config.xml, the plugin now has a new variable with a blank description that you can fill in - now build ios with -- release and they will be set.

    0 讨论(0)
  • 2020-11-28 22:14

    This does seem to be possible now using the config.xml: at least some core plugin authors say so. For instance, in the docs for the Cordova Camera Plugin, they discuss the new requirement in iOS 10 that you provide a permission message string in the plist. To accomplish it, they suggest executing the plugin add command with arguments, thus:

    cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="My App would like to access your camera, to take photos of your documents."

    This has the result that you not only get a new <plugin> added to config.xml, but it has a <variable> child:

    <plugin name="cordova-plugin-camera" spec="~2.3.0">
        <variable name="CAMERA_USAGE_DESCRIPTION" value="My App would like to access your camera, to take photos of your documents." />
    </plugin>
    

    Which then seems to correlate to the new keys in my info.plist, perhaps somehow passing the values at runtime?

      <key>NSCameraUsageDescription</key>
      <string/>
      <key>NSPhotoLibraryUsageDescription</key>
      <string/>
    

    I'd be lying if I said that I know exactly how it works, but it seems to point the way.

    0 讨论(0)
提交回复
热议问题