How to change an Info.plist flag based on the TARGET_OS?

462 Views Asked by At

I'm attempting to migrate my iOS app to support builds for the UIKitForMac target (project Catalyst!).

I'm attempting to change an Info.plist flag based on the TARGET_OS, but I'm not sure how can I detect the target OS from a build phase's run script. Here is what I'm trying to do:

echo "[DEBUG-PRINT] ---> Update flag"
if [ ${TARGET_OS_UIKITFOTMAC} ]; then
echo "[DEBUG-PRINT] ---> IF succeeded"
/usr/libexec/PlistBuddy -c "Set :LSSupportsOpeningDocumentsInPlace YES" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
fi

What am I doing wrong? Any ideas?

1

There are 1 best solutions below

0
marcelosalloum On BEST ANSWER

I ended up adding a pre-action run script to my scheme:

#!/bin/sh
INFO_PLIST="$INFOPLIST_FILE"
RAW_BUNDLE_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$INFO_PLIST")
if [[ $OTHER_SWIFT_FLAGS == *"-D TARGET_OS_UIKITFORMAC"* ]] && [[ $RAW_BUNDLE_ID != uikitformac* ]]; then
    /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier uikitformac.$RAW_BUNDLE_ID" "$INFO_PLIST"
elif [[ $OTHER_SWIFT_FLAGS != *"-D TARGET_OS_UIKITFORMAC"* ]] && [[ $RAW_BUNDLE_ID == uikitformac* ]]; then
    /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier ${RAW_BUNDLE_ID#'uikitformac.'}" "$INFO_PLIST"
fi