Skip to content

Instantly share code, notes, and snippets.

@Ashton-W
Last active October 15, 2022 03:46
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Ashton-W/07654259322e43a2b6a50bb289e72627 to your computer and use it in GitHub Desktop.
Save Ashton-W/07654259322e43a2b6a50bb289e72627 to your computer and use it in GitHub Desktop.
Xcode Build Phase Script to remove NSAppTransportSecurity from the Info.plist based on the custom REMOVE_ATS_EXCEPTIONS build setting.
#!/usr/bin/env bash
# Build Phase Script for removing NSAppTransportSecurity exceptions from Info.plist
# https://gist.github.com/Ashton-W/07654259322e43a2b6a50bb289e72627
set -o errexit
set -o nounset
if [[ -z "${REMOVE_ATS_EXCEPTIONS+SET}" ]]; then
echo "error: User Defined Build Setting REMOVE_ATS_EXCEPTIONS must be set"
exit 1
fi
#
remove_ATS_exceptions() {
if [ "$REMOVE_ATS_EXCEPTIONS" == "YES" ]; then
local infoplist="$CODESIGNING_FOLDER_PATH/Info.plist"
local -r ats_present=$(/usr/libexec/PlistBuddy -c "Print :NSAppTransportSecurity" "$infoplist" 2>/dev/null)
if [ "$ats_present" ]; then
/usr/libexec/PlistBuddy -c "Delete :NSAppTransportSecurity" "$infoplist"
touch "$infoplist"
echo "Removed NSAppTransportSecurity from Info.plist"
else
echo "No NSAppTransportSecurity found in Info.plist"
fi
else
echo "REMOVE_ATS_EXCEPTIONS not enabled for $CONFIGURATION. Did not remove NSAppTransportSecurity from Info.plist"
fi
}
remove_ATS_exceptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment