Skip to content

Instantly share code, notes, and snippets.

@johnboiles
Last active January 28, 2021 07:48
Show Gist options
  • Save johnboiles/91ae8f64c2dbb49807f4 to your computer and use it in GitHub Desktop.
Save johnboiles/91ae8f64c2dbb49807f4 to your computer and use it in GitHub Desktop.
Add this as a "Run Script" build phase in Xcode to enable Charles Proxy on iOS 9
#!/bin/sh
# enable-charles-proxy.sh
#
# Created by John Boiles on 9/21/15.
#
# This script sets :NSAppTransportSecurity:NSAllowsArbitraryLoads to true in the Info.plist file if building the Debug configuration.
# This enables debugging from https proxies such as Charles.
INFO_PLIST="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
PLISTBUDDY="/usr/libexec/PlistBuddy"
if [ "${CONFIGURATION}" == "Debug" ]; then
$PLISTBUDDY -c "Add :NSAppTransportSecurity dict" "${INFO_PLIST}" || true
$PLISTBUDDY -c "Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool true" "${INFO_PLIST}" || true
$PLISTBUDDY -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads true" "${INFO_PLIST}"
else
$PLISTBUDDY -c "Delete :NSAppTransportSecurity:NSAllowsArbitraryLoads" "${INFO_PLIST}" || true
fi
ALLOWS_ARBITRARY_LOADS_ENABLED=$($PLISTBUDDY -c "Print :NSAppTransportSecurity:NSAllowsArbitraryLoads" "${INFO_PLIST}")
if [ "${ALLOWS_ARBITRARY_LOADS_ENABLED}" == "true" ]; then
echo "Warning: :NSAppTransportSecurity:NSAllowsArbitraryLoads set to true (potentially insecure)."
fi
@nicholascross
Copy link

If you want this script to work consistently remember to specify in the input files the following $(TARGET_BUILD_DIR)/$(INFOPLIST_PATH). This ensures things happen in the correct order.

I was experiencing a problem where it would work on clean build but all incremental builds would fail due to the plist file change being overridden by the original plist file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment