How to auto-increment Bundle Version in Xcode 4?

后端 未结 9 910
情书的邮戳
情书的邮戳 2020-12-12 16:43

I am trying to figure out how to have the Bundle version number increment automatically in my Xcode 4 project (for ad-hoc and release builds). I found some scripts online th

9条回答
  •  再見小時候
    2020-12-12 17:05

    This might help you. I am using it in my projects. https://gist.github.com/alokc83/5207294

    #!/bin/sh
    # xcode-build-number-generator.sh
    # @desc Automaticvally create build number every time using curent day, month and year
    # @usage
    # 1. Select: your Target in Xcode
    # 2. Select: Build Phases Tab
    # 3. Select: Add Build Phase -> Add Run Script
    # 4. Paste code below in to new "Run Script" section
    # 5. Drag the "Run Script" below "Link Binaries With Libraries"
    
    
    #Credits 
    # sekati@github for intial direction about automatic versioning
    # http://www.codinghorror.com/blog/2007/02/whats-in-a-version-number-anyway.html (For unferstanding the Software Versoining)
    #Feel free to leave comment or report issues
    
    
    MONTH=`date | awk '{print $2}'`
    
    case "$MONTH" in
      'Jan' )
             MONTHNUMBER=1
         ;;
        'Feb' )
             MONTHNUMBER=2
        ;;
        'Mar' )
        MONTHNUMBER=3
        echo "Month is $MONTHNUMBER"
        ;;
        'Apr' )
             MONTHNUMBER=4
        ;;
        'May' )
             MONTHNUMBER=5
            ;;
        'Jun' )
             MONTHNUMBER=6
            ;;
        'Jul' )
             MONTHNUMBER=7
            ;;
        'Aug' )
             MONTHNUMBER=8
            ;;
        'Sep' )
             MONTHNUMBER=9
            ;;
        'Oct' )
             MONTHNUMBER=10
            ;;
        'Nov' )
             MONTHNUMBER=11
            ;;
        'Dec' )
             MONTHNUMBER=12
            ;;
    esac
    
    DATE=`date | awk '{print $3}'`
    echo "Date = $DATE"
    YEAR=`date | awk '{print $6}'`
    echo "Date = $YEAR"
    
    ### only uncomment section below if testing the format in terminal
    #echo "BuildNumber1 = $MONTH$DATE$YEAR"
    #echo "or BUILD NUMBER = $DATE$MONTH$YEAR"
    #echo "or BUILD NUMBER = $MONTHNUMBER$DATE$YEAR Format is |Month Number Date Year|"
    #echo "or BUILD NUMBER = $DATE$MONTHNUMBER$YEAR format is |Date MonthNumber Year|"
    ############################
    
    #### Uncomment only one one style or last one will be in effect
    #buildNumber=$MONTH$DATE$YEAR
    #buildNumber=$DATE$MONTH$YEAR
    buildNumber=$MONTHNUMBER$DATE$YEAR
    #buildNumber=$DATE$MONTHNUMBER$YEAR
    
    
    echo "Final Build number is $buildNumber"
    ## Below command write buildNumber in the property list
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
    

提交回复
热议问题