edoloughlin
edoloughlin

Reputation: 5901

Setting a boolean property in Info.plist from a User Defined Setting

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.

Upvotes: 43

Views: 19064

Answers (4)

rgkobashi
rgkobashi

Reputation: 2698

In my case I had to use Add action so I can define that the value I want is bool:

/usr/libexec/PlistBuddy -c "Add :UIFileSharingEnabled bool ${FILE_SHARING_ENABLED}" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"

In my case FILE_SHARING_ENABLED comes from a xcconfig file.

Upvotes: 0

gasparuff
gasparuff

Reputation: 2295

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.

Upvotes: 11

Ken Aspeslagh
Ken Aspeslagh

Reputation: 11594

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.

Upvotes: 19

Louis Gerbarg
Louis Gerbarg

Reputation: 43452

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.

Upvotes: -7

Related Questions