Campbell_Souped
Campbell_Souped

Reputation: 881

How do you change App Transport Security Settings based on the build configuration?

I have an app with multiple build configurations. If the selected configuration is Debug, I want NSAllowsArbitraryLoads key in the Info.plist file to be set as YES, else I want it to be set as NO.

How do I go about achieving this?

Upvotes: 4

Views: 887

Answers (1)

Campbell_Souped
Campbell_Souped

Reputation: 881

The solution I found requires the use of PlistBuddy:

In your project settings, select Build Phase > click + to add a new run script build phase.

Name the phase "App Transport Security". Paste the following script:

if [ "${CONFIGURATION}" = "Release" ]; 
then 
    /usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads false" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" 
else 
    /usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads true" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" 
fi

Upvotes: 5

Related Questions