I'm working on a development environment without HTTPS setup. Is it possible to automatically disable ATS just for the development (debug) mode?
My solution is to keep ATS disable option at the default NO value and add a New Run Script Phase to change it in the app bundle's Info.plist when building the app.
This is the script:
#Disables ATS in debug builds.
INFOPLIST="${TARGET_BUILD_DIR}"/"${INFOPLIST_PATH}"
case "${CONFIGURATION}" in
"Release"|"Adhoc")
/usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads NO" "${INFOPLIST}"
;;
"Debug")
/usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads YES" "${INFOPLIST}"
;;
esac
Another solution. By using INFOPLIST_PREPROCESS = YES
and INFOPLIST_PREPROCESSOR_DEFINITIONS = DEBUG=1
,
it can be conditional preprocess like C code using #ifdef
or #if
directly in Info.plist.
<key>UIMainStoryboardFile</key>
<string>Main</string>
#if DEBUG
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
#endif
<key>UIRequiredDeviceCapabilities</key>
<array>
Cons: Unable to open Xcode's property list editor because it is not well-formed XML :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With