8

For my application, I need to add some settings to the Info.plist file for iOS. I thought the best way to do this, would be to add these settings to my config.xml file (I'm using PhoneGap). When I add the following to the config.xml file and run

cordova build ios

or

cordova update platform ios

Nothing is added to my Info.plist file, and I absolutely have no idea why that is. The build show 'success', so I don't think there's a syntax error.

I've tried:

<platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
    <config-file target="*-Info.plist" parent="NSAppTransportSecurity">
        <array>
            <dict>
                <key>NSExceptionDomains</key>
                <array>
                    <dict>
                        <key>s3.amazonaws.com</key>
                        <array>
                            <dict>
                                <!--Include to allow subdomains-->
                                <key>NSIncludesSubdomains</key>
                                <true/>
                                <!--Include to allow insecure HTTP requests-->

<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                                <true/>
                                <!--Include to specify minimum TLS version-->
                                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                                <string>TLSv1.1</string>
                            </dict>
                        </array>
                    </dict>
                </array>
            </dict>
        </array>
    </config-file>
</platform>

And

<platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
    <config-file target="*-Info.plist" parent="NSAppTransportSecurity">
        <dict>
            <key>NSExceptionDomains</key>
                <dict>
                <key>s3.amazonaws.com</key>
                <dict>
                    <!--Include to allow subdomains-->
                    <key>NSIncludesSubdomains</key>
                    <true/>
                    <!--Include to allow insecure HTTP requests-->
                    <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                    <true/>
                    <!--Include to specify minimum TLS version-->
                    <key>NSTemporaryExceptionMinimumTLSVersion</key>
                    <string>TLSv1.1</string>
                </dict>
            </dict>
        </dict>
    </config-file>
</platform>

And

<gap:config-file platform="ios" parent="NSAppTransportSecurity">
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>s3.amazonaws.com</key>
            <dict>
                <!--Include to allow subdomains-->
                <key>NSIncludesSubdomains</key>
                <true/>
                <!--Include to allow insecure HTTP requests-->
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <!--Include to specify minimum TLS version-->
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
        </dict>
    </dict>
</gap:config-file>

And

<gap:config-file platform="ios" parent="NSAppTransportSecurity">
    <array>
        <dict>
            <key>NSExceptionDomains</key>
            <array>
                <dict>
                    <key>s3.amazonaws.com</key>
                    <array>
                        <dict>
                            <!--Include to allow subdomains-->
                            <key>NSIncludesSubdomains</key>
                            <true/>
                            <!--Include to allow insecure HTTP requests-->

                            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                            <true/>
                            <!--Include to specify minimum TLS version-->
                            <key>NSTemporaryExceptionMinimumTLSVersion</key>
                            <string>TLSv1.1</string>
                        </dict>
                    </array>
                </dict>
            </array>
        </dict>
    </array>
</gap:config-file>

But nothing is added to the Info.plist file. What am I doing wrong here?

Flock Dawson
  • 1,762
  • 3
  • 21
  • 32
  • possible duplicate of [Add entry to iOS .plist file via Cordova config.xml](http://stackoverflow.com/questions/22769111/add-entry-to-ios-plist-file-via-cordova-config-xml) – lifeisfoo Sep 14 '15 at 09:30

1 Answers1

5

I achieve this using a build hook for iOS. So, in config.xml I'd put something like:

<hook type="before_build" src="../scripts/ios_before_build.sh" />

Inside the:

 <platform name="ios">

element in config.xml

Then I'd create a file called ../scripts/ios_before_build.sh, make sure it has execute permissions (chmod 755 ../scripts/ios_before_build.sh) then set the script to use PlistBuddy to make required changes to the .plist file.

For example here I am turning off iOS 9 requirement for SSL secured backend URLs as the API for the app I was developing doesn't use https:

val=$(/usr/libexec/plistbuddy -c "add NSAppTransportSecurity:NSAllowsArbitraryLoads bool true" platforms/ios/AppName/AppName-Info.plist 2>/dev/null)

I'm suppressing the return code of plistbuddy as it will fail if the item exists already. Here I'm adding a dict and setting a boolean value but you can do a variety of other stuff as per PlistBuddy documentation.

Then when you do:

cordova build ios

The script will be run, alter your plist then the cordova build will continue.

I find this cleaner as I don't like to have the platforms or plugins folder checked into version control on my Cordova projects.

Simon Prickett
  • 2,647
  • 1
  • 11
  • 26
  • 1
    ios_before_build.sh will probably need the first line to be "#! /usr/bin/env bash" otherwise it will say "command not found" when the hook is run – Jim W says reinstate Monica Oct 12 '15 at 17:39
  • @Simon Prickett HI, can you explain how to create the .sh file? I am on windows. I am using phonegap build to compile my app. I uploaded it with Application Loader and got an error saying "Missing Info.plist key...The app's Info.plist must contain an NSPhotoLibraryUsageDescription key..." I have no idea how to work with the plist so your help would be appreciated. – Sarah Feb 21 '17 at 17:36
  • For Windows, you aren't going to have access to the Apple tools to maintain plist files at the command line. I'd recommend looking at doing this with a Python script or similar, and maybe use a module such as https://docs.python.org/2/library/plistlib.html to help. I don't use Windows, so can't try this out, but that's an approach I'd look to take. – Simon Prickett Feb 21 '17 at 18:53
  • @SimonPrickett Thanks. unfortunately im not familiar with python at all. i've built my app with javascript, Jquery, html and css. I will investigate further. thanks for the help. – Sarah Feb 21 '17 at 20:39
  • @SimonPrickett Actually ive just realised I have access to a mac environment as I am using macincloud to upload my ipa file to the app store anyway. So could I create the .sh file there with command prompt? – Sarah Feb 21 '17 at 20:48