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?
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>