Detailed Explanation of version and build in iOS Project

  • 2021-07-03 00:56:28
  • OfStack

version and build in the iOS project

Version key in the plist file is "CFBundleShortVersionString", which identifies the release version number of the application, and the version number on AppStore remains 1. The version number of this version is a string composed of 3 separated integers. The 1st integer represents a significant revision, such as a revision that implements new functions or major changes. The second integer represents the revision, which realizes the more prominent features. The 3rd integer represents the maintenance version

Build key in the plist file is "CFBundleVersion", indicating the build number (released or unreleased). This is a monotonically increasing string, including one or more divided integers.

The above two version numbers can be obtained in the following ways:


NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; 
  
// app Version  
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; 
  
// app build Version  
NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"]; 

Write a script to automatically increase the build version number after Archive

If we want the build number to grow automatically after Archive, we can use run script of Xcode to realize it. The steps are as follows

Select target of the project and click "Build Phases" Click "Add Build Phrase" in the lower right corner and select "Add run script" to generate a new Run Script item Drag the newly generated Run Script item to the top Click on this item, and the shell code below copy goes in, and the code comes from here, as shown in the following figure


if [ $CONFIGURATION == Release ]; then 
  echo "Bumping build number..." 
  plist=${PROJECT_DIR}/${INFOPLIST_FILE} 
 
  #increment the build number (ie 115 to 116) 
  buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}") 
  if [[ "${buildnum}" == "" ]]; then 
    echo "No build number in $plist" 
    exit 2 
  fi 
 
  buildnum=$(expr $buildnum + 1) 
  /usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "${plist}" 
  echo "Bumped build number to $buildnum" 
 
else 
  echo $CONFIGURATION " build - Not bumping build number." 
fi 

This shell script means that if the current configuration is Release (Release for Archive, Debug for running directly on the emulator), set the build value to the current build value +1, otherwise do nothing.

In this way, when build, you will see that build will automatically add 1. If you want to see the output information when build, you can pass "View- > Navigators - > Log "to see the log generated with the latest build.

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: