How to read current app version in Xcode 11 with script

前端 未结 9 1743
野趣味
野趣味 2020-12-14 00:38

Until Xcode 11, I used a script that reads the current app version (for the AppStore) and help me change the LaunchScreen since we can\'t use swift for that

相关标签:
9条回答
  • 2020-12-14 01:24

    Xcode 11/12

    In terminal or bash script in your project you can use:

    App version

    xcodebuild -showBuildSettings | grep MARKETING_VERSION | tr -d 'MARKETING_VERSION =' // will be displayed 1.1.6

    Build version

    xcodebuild -showBuildSettings | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION =' // will be displayed 7

    Or (don't forget to change YouProjectName to your project name):

    App version

    cat YouProjectName.xcodeproj/project.pbxproj | grep -m1 'MARKETING_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' '

    Build version

    cat YouProjectName.xcodeproj/project.pbxproj | grep -m1 'CURRENT_PROJECT_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' '

    Or slower method (Thx Joshua Kaden):

    App version

    xcodebuild -project YouProjectName.xcodeproj -showBuildSettings | grep "MARKETING_VERSION" | sed 's/[ ]*MARKETING_VERSION = //'

    Build version

    xcodebuild -project YouProjectName.xcodeproj -showBuildSettings | grep "CURRENT_PROJECT_VERSION" | sed 's/[ ]*CURRENT_PROJECT_VERSION = //'

    0 讨论(0)
  • 2020-12-14 01:26

    I'm developing a framework with this scenario:

    • A workspace
    • A framework target
    • An aggregate target with 2 external scripts:
      • one for build a fat framework
      • other for prepare the release framework

    The key is that in XCode 11 the aggregate framework script doesn't get run environment variables for other workspace targets so it's impossible to read the $MARKETING_VERSION from my framework target.

    So the solution that works for me has been use PlistBuddy specifying the Info.plist result of the framework target build in this way:

    FAT_FRAMEWORK="${SRCROOT}/build/${FRAMEWORK_NAME}.framework"
    BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${FAT_FRAMEWORK}/Info.plist")
    VERSION_NUMBER=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${FAT_FRAMEWORK}/Info.plist")
    
    0 讨论(0)
  • 2020-12-14 01:30

    If you use Bitrise then the following script will save you:

    Extracting App Marketing Version

    envman add --key=APP_VERSION_NO --value=`sed -n '/MARKETING_VERSION/{s/MARKETING_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' ./${PATH_TO_YOUR_PROJECT_XCODEPROJ_FILE}/project.pbxproj`

    Extracting App Build Number

    Extract the Build Number from xcodeproj file only if you use Apple Generic versioning system otherwise extract the Build Number from the XCode project info.plist file.

    Note: The following script extracts the Build Number from the xcodeproj file.

    envman add --key=APP_BUILD_NO --value=`sed -n '/CURRENT_PROJECT_VERSION/{s/CURRENT_PROJECT_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' ./${PATH_TO_YOUR_PROJECT_XCODEPROJ_FILE}/project.pbxproj`

    Printing to console:

    envman run bash -c 'echo "App Version: $APP_VERSION_NO"'

    envman run bash -c 'echo "App Build No: $APP_BUILD_NO"'

    Thanks to the answer by @babac

    0 讨论(0)
提交回复
热议问题