ToIOS ApplicationAdd Automatic UpdatesAttributeIs the content to be introduced in this article, inIOSIn projects, you can add custom settings in Info. plist to facilitate tracking of released versions and debugging, or to display program compilation dates.AttributeBut this work is purely mechanical and repetitive, and every manual update is a troublesome task.
Fortunately, the Xcode project supports the compilation steps of custom scripts. we can update Info. plist by using custom scripts during the compilation process.
Under the/usr/libexec directory, there is a tool PlistBuddy, which can easily modify the plist file without the need to use an editing tool such as sed to modify it.
In order to directly Set properties using the Set command when using PlistBuddy, we first Set the properties in the iOS project's Info. in plist, add an attribute that needs to be automatically updated, such as BUILD_DATE and GIT_REVISION. Set the type to string and set the value to AUTO_GENERATED.
Then add a new compilation step Run Script Build Phase on the Target of the iOS project:
The next page is to write scripts.
# Get the compilation date
- DATE=`date +%Y.%m.%d`
# Obtain the short version number of the Git library during compilation
- GIT_REVISION=`git rev-parse --short HEAD`
# Set related properties in Info. plist
- /usr/libexec/PlistBuddy "$TARGET_BUILD_DIR/$INFOPLIST_PATH" -c "Set BUILD_DATE $DATE"
- /usr/libexec/PlistBuddy "$TARGET_BUILD_DIR/$INFOPLIST_PATH" -c "Set GIT_REVISION $GIT_REVISION"
# Convert Info. plist to binary format
- plutil -convert binary1 "$TARGET_BUILD_DIR/$INFOPLIST_PATH"
If you need to obtain these attributes in the program, you can use the following method:
- NSString *buildDate = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"BUILD_DATE"];
- NSString *revision = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"GIT_REVISION"];
Summary:IOS ApplicationAdd Automatic UpdatesAttributeI hope this article will help you.