1

I can edit a plist programatically but I would like to modify the plist ONLY per session and I'm hoping there's a better way to accomplish what I'm wanting to do. Here's what I'm hoping to accomplish

When _DEV is defined (#define _DEV) I want the following plist variable to change:

NSAllowsArbitraryLoads from NO to YES

Reason being because our dev server doesn't have an https certificate, but when _DEV is not defined I want the app to only allow https activity.

As of now I manually have to change this value in my plist, which is fine, but I'd prefer to have this be dynamic. Is the only way to modify the plist or is there another way to change this value during runtime?

Community
  • 1
  • 1
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284

1 Answers1

5

You can use a run script and a user defined attribute to toggle App Transport Security for your different build configurations (Debug, Release, ...).

#!/bin/bash

if [ $XYZDisableAppTransportSecurity == YES ]; then

echo "Disabling App Transport Security..."

TARGET_INFOPLIST_PATH="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"

$(/usr/libexec/PlistBuddy -c "Delete NSAppTransportSecurity" "${TARGET_INFOPLIST_PATH}" 2> /dev/null)
/usr/libexec/Plistbuddy -c "Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool true" "${TARGET_INFOPLIST_PATH}"

fi

Note that the run script modifies the Info.plist file in the target folder of the created build. That means your local project remains untouched.

bernhard
  • 277
  • 3
  • 6
  • If XYZDisableAppTransportSecurity is defined in the build settings: user defined variables, in the script use ${XYZDisableAppTransportSecurity}, plus I didn't need the "2> /dev/null)" part.. otherwise works #1 thank you – Marc Feb 10 '21 at 21:41