Search code examples
xcodebuildrun-scriptinfo-plistuikitformac

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


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?


Solution

  • 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