How to get your own app version from xcode?

前端 未结 4 1897
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 15:30

I wonder if there is a way to get your own app version in code after you put it in the \"Summary\" tab in xCode. One way seems to be to search Info.plist for

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-31 15:38

    I typically use the Build number (CFBundleVersion) to keep track of, well, the number of builds, and the Version number (CFBundleShortVersionString) for marketing purposes. I use a run script to auto-increment my build number and I update the version number manually before each new release. So if you want to include the actual Version number in your code as opposed to the Build number, use this:

    [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
    

    or

    [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
    

    Here's the run script that increments the build number for anyone interested:

    #!/bin/bash
    
    buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
    buildNumber=$(($buildNumber + 1))
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
    

提交回复
热议问题