Is it possible to disable ATS in iOS 9 just for de

2019-01-09 09:08发布

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

标签: ios9 xcode7
3条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-09 09:51

Another solution. By using INFOPLIST_PREPROCESS = YES and INFOPLIST_PREPROCESSOR_DEFINITIONS = DEBUG=1,

enter image description here

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楼-- · 2019-01-09 10:09

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.

enter image description here

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
查看更多
等我变得足够好
4楼-- · 2019-01-09 10:13

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

查看更多
登录 后发表回答