41

It's simple to set a property in an Info.plist file from a user defined setting, you just use ${YOUR_SETTING_NAME} as the value. However, is it possible to do this for a bolean property? The structure in the plist file for a boolean is:

<key>NSAppleScriptEnabled</key>
<false/>

It's not clear how to use a user defined setting here.

edoloughlin
  • 5,821
  • 4
  • 32
  • 61

3 Answers3

17

I'm not sure how to do what you're asking, but I'm pretty sure that for this particular key (NSAppleScriptEnabled) you can also use strings "YES" and "NO" and it will work.

Ken Aspeslagh
  • 11,484
  • 2
  • 36
  • 42
  • 3
    It works if you set the variable (setting) type in Info.plist to String (not boolean) and then use 'YES' and 'NO'. Thanks. – edoloughlin Dec 02 '09 at 21:47
  • 14
    Xcode does not allow you to change the variable type for built-in keys. For example, I am trying to turn off App Transport Security for development builds so I can use SSL proxying with Charles proxy. The "Allows Arbitrary Loads" key cannot be changed from boolean. What does one do in that case? – josephap Apr 19 '16 at 19:55
  • 3
    I have the same issue with UIFileSharingEnabled key. While Xcode allows me the change the key type to String and it builds and runs fine in Xcode, I get an error when submitting the app to AppStore. – ejel Apr 25 '16 at 18:23
  • 1
    It doesn't work for `App Transport Security` Key which require a boolean, check this answer: http://stackoverflow.com/questions/32390228/is-it-possible-to-disable-ats-in-ios-9-just-for-debug-environment – Hugues BR Jul 06 '16 at 14:59
  • 1
    It's funny how much everyone is focusing on the specific key OP shared, it was just an example. He's talking about setting a Bool for a custom, user defined env variable. Unfortunately you can't set bools for these, you need to use a string and then convert to bool later if you want. – user3344977 Oct 19 '16 at 18:23
11

plist files containing booleans within tags are not valid any more.

This solution works:

Add a new Run Script Build Phase to your target. Put in this:

if [ ${CONFIGURATION} = "Release" ]; then
/usr/libexec/PlistBuddy -c "Set :UIFileSharingEnabled NO" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
fi

So in my configuration, I'm setting the UIFileSharingEnabled to YES in my plist as a default and when I'm building for Release, then the step above happens and sets it to false.

gasparuff
  • 2,295
  • 29
  • 48
  • More details in [this answer](https://stackoverflow.com/a/32704702/1417451) and the comments on it. This modifies the plist in the app bundle, so it doesn't dirty your repo. – s3cur3 May 19 '20 at 14:00
-6

What do you mean by "User Defined Setting" ...

If the user you are talking about is you (in other words, the app's developer), then you can just put whatever keys you want there, just like any other plist in your Xcode project.

If the user you are talking about is your app's end user, don't try to save their settings in your Info.plist. It is a part of the application. While it is sometimes possible for an app to change its own info plist on a mac, it often is not, depending on how the app was installed. On the iPhone it is never possible, since the app is read-only. In either event, changing your Info.plist would invalidate any app signing you have done.

If you want to change end user settings, use something NSUserDefaults.

Louis Gerbarg
  • 43,356
  • 8
  • 80
  • 90
  • Hi Louis. I believe he's talking about a user-defined XCode Build setting on the Mac. – Ken Aspeslagh Dec 02 '09 at 15:35
  • 2
    See the accepted answer above. I have multiple targets in the project sharing a single Info.plist. I'm using User Defined Settings on each target to configure the values in Info.plist. One of them is a boolean and it's not (or wasn't) clear how to substitute these. – edoloughlin Dec 02 '09 at 21:52