1

I am trying to adopt iOS9 ATS support in my app. For that the following code will work for sure

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>YOURHOST.COM</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>1.0</string>
            <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
   </dict>
</dict>

But the problem here is that I have defined the server URL in xcconfig file which are different for development and distribution environment.

So, the problem here is that I want to get the server URLs from xcconfig file which will serve as key names in place of 'YOURHOST.COM' in above code.

So when I try to fetch the server URL as

${SERVER_URL} , I get the following error as

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

This clearly means that the key name is not properly taken , on the other hand if I directly set the key value here, it works perfectly.

My xcconfig file contains following code:

SERVER_URL=myserverUrl.com

I am unable to set the key name which I have to directly take from xcconfig file.

How can I do that?

SandeepAggarwal
  • 1,273
  • 3
  • 14
  • 38

2 Answers2

5

You can enable preprocessing for plist files.

This helped me to handle it: http://ilya.puchka.me/info-plist-preprocessing/

1) Enable Build Settings -> "Preprocess Info.plist File"

2) Add your preprocessor definitions at "Info.plist Preprocessor Definition" (of cause you can also define it your xcconfig)

INFOPLIST_PREPROCESSOR_DEFINITIONS = $(inherited) CONFIG_DOMAIN=$(SERVER_URL)

3) If you use URLs in your plist add "-traditional" in "Info.plist Other Preprocessor Flags" (see https://developer.apple.com/library/mac/technotes/tn2175/_index.html#//apple_ref/doc/uid/DTS10004415-CH1-TNTAG3)

For other issues at preprocessing the Info.plist you can get some help here Xcode "Cannot parse contents of Info.plist"

Now you can use the preprocessed definition as key in your plist

<key>CONFIG_DOMAIN</key>
Community
  • 1
  • 1
Tine74
  • 66
  • 2
  • Your solution worked very well , but I want to know what did you meant by this statement ' (of cause you can also define it your xcconfig)' ?? – SandeepAggarwal Jan 01 '16 at 08:59
3

To propagate a setting from .xcconfig to Info.plist, I have a different experience, and a different answer. The accepted answer by Tine74 may well be correct, or may have been correct under some circumstances, because Xcode's Info.plist preprocessing feature has been buggy and unpredictable for years. The following applies today, to Xcode Version 8.2 (8C38).

• Define the setting in your .xcconfig file. Example:

FOO = 14

• In the product target's Build Settings, scroll to the bottom and verify that Xcode has added a User-Defined Build Setting with the same name, and value you set in the .xcconfig file in the "Resolved" and "Config. File" columns. Following the same example, the new row looks like this

FOO 14 14

The two numbers "14" are in faint disabled text color, to indicate that they come from elsewhere (the .xcconfig file).

• In the target's Info.plist file, reference the symbol name using a dollar sign and curly brackets. Continuing the example:

MySetting String ${FOO}

• Finally, in order for the current value in your .xcconfig file to appear in the Info.plist file after the next build (MySetting = 14), you must close and reopen the Xcode project before the next build. This appears to be a bug in Xcode. Trashing the Info.plist file in the product does not help. Cleaning the target does not help. Building two or three times does not help. You must close and reopen the Xcode project.

The accepted answer by Tine74, setting Info.plist Preprocessor Definition, did not work for me so I deleted that setting. However, that is before I discovered the close/reopen trick. Maybe Tine74's answer would work with that trick.

Jerry Krinock
  • 4,860
  • 33
  • 39