Is it possible to disable ATS in iOS 9 just for debug environment?

女生的网名这么多〃 提交于 2019-12-17 09:46:15

问题


I'm working on a development environment without HTTPS setup. Is it possible to automatically disable ATS just for the development (debug) mode?


回答1:


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



回答2:


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 :(




回答3:


Yes, you can configure your project settings to use different Info.plist file for Debug, Release or whatever configuration you use in your project (similar to the way Provisioning Profiles are set), so in your Debug plist you can disable ATS totally.

Go to Project -> Your Target -> Build Settings -> Info.plist File



来源:https://stackoverflow.com/questions/32390228/is-it-possible-to-disable-ats-in-ios-9-just-for-debug-environment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!