Add auto update attributes to iOS apps

Source: Internet
Author: User

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

 
 
  1. DATE=`date +%Y.%m.%d` 

# Obtain the short version number of the Git library during compilation

 
 
  1. GIT_REVISION=`git rev-parse --short HEAD` 

# Set related properties in Info. plist

 
 
  1. /usr/libexec/PlistBuddy "$TARGET_BUILD_DIR/$INFOPLIST_PATH" -c "Set BUILD_DATE $DATE"  
  2. /usr/libexec/PlistBuddy "$TARGET_BUILD_DIR/$INFOPLIST_PATH" -c "Set GIT_REVISION $GIT_REVISION" 

# Convert Info. plist to binary format

 
 
  1. plutil -convert binary1 "$TARGET_BUILD_DIR/$INFOPLIST_PATH" 

If you need to obtain these attributes in the program, you can use the following method:

 
 
  1. NSString *buildDate = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"BUILD_DATE"];  
  2. NSString *revision = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"GIT_REVISION"]; 

Summary:IOS ApplicationAdd Automatic UpdatesAttributeI hope this article will help you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.