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

后端 未结 15 1329
日久生厌
日久生厌 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:35

    You can use the PlistBuddy utility inside a Cordova hook script to modify the *-Info.plist file.

    For example, I have the following script under /hooks/after_prepare/010_modify_plist.sh which adds a dictionary property and adds an entry within that dictionary:

    #!/bin/bash
    
    PLIST=platforms/ios/*/*-Info.plist
    
    cat << EOF |
    Add :NSAppTransportSecurity dict
    Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool YES
    EOF
    while read line
    do
        /usr/libexec/PlistBuddy -c "$line" $PLIST
    done
    
    true
    

    Be sure to make the script executable (chmod +x).

    The true at the end of the script is because PlistBuddy returns with an error exit code if the key being added already exists, and doesn't provide a way to detect if the key already exists. Cordova will report a build error if the hook script exits with an error status. Better error handling is possible but a pain to implement.

提交回复
热议问题