How to read current app version in Xcode 11 with script

前端 未结 9 1780
野趣味
野趣味 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:21

    Couldn't find right answer on the internet, so I started digging.

    Version and build numbers are displayed in ./PROJECTNAME.xcodeproj/project.pbxproj as MARKETING VERSION (MV) and CURRENT PROJECT VERSION (CPV).

    I used sed to get the numbers. It finds first occurrence of MV or CPV, removes everything except the number, and returns result. In order for this to work, you need to do 2 things:

    • navigate to projects root folder
    • change PROJECTNAME to your project's name

    Commands:

    version_number=`sed -n '/MARKETING_VERSION/{s/MARKETING_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' ./PROJECTNAME.xcodeproj/project.pbxproj`
    build_number=`sed -n '/CURRENT_PROJECT_VERSION/{s/CURRENT_PROJECT_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' ./PROJECTNAME.xcodeproj/project.pbxproj`
    

    Result:

    Note: If you have more targets in your workspace with different version and build numbers, this might or might not work for you, because it stops on first occurrence. In that case, good luck :)

提交回复
热议问题