Dynamically modify the app build version CFBundleVersion

1, demand explanation

2, Procedure

  • 2.1 New Script, select the Build Phases

  • 2.2 Click the plus sign and select New Run Script Phase

  • 2.3 for easy identification, double rename Dynamic Build Version

  • 2.4 Paste the following code, note the contents to be modified

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "${$(SRCROOT)}/${INFOPLIST_FILE}")
buildNumber=`date +"%Y%m%d%H%M"`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
  • 2.5 code runs acquisition

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
// app build版本
NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
NSLog(@"app_build == %@", app_build);
  • So far, the project can also be seen in the compiled version is modified

Guess you like

Origin www.cnblogs.com/CH520/p/10197181.html