How can I display the application version revision in my application's settings bundle?

前端 未结 13 805
一个人的身影
一个人的身影 2020-11-29 15:20

I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application\'s settings bundle.

The Root.plist file contai

13条回答
  •  暖寄归人
    2020-11-29 15:49

    My working Example based on @Ben Clayton answer and the comments of @Luis Ascorbe and @Vahid Amiri:

    Note: This approach modifies the Settings.bundle/Root.plist file in working copy of repository

    1. Add a settings bundle to your project root. Don't rename it

    2. Open Settings.bundle/Root.plist as SourceCode

      Replace the contents with:

      
      
      
      
          PreferenceSpecifiers
          
              
                  DefaultValue
                  
                  Key
                  version_preference
                  Title
                  Version
                  Type
                  PSTitleValueSpecifier
              
          
          StringsTable
          Root
      
      
      
    3. Add the following script to the Build, Pre-actions section of the project (target) scheme

      version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PROJECT_DIR/$INFOPLIST_FILE")
      build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$PROJECT_DIR/$INFOPLIST_FILE")
      
      /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:0:DefaultValue $version ($build)" "${SRCROOT}/Settings.bundle/Root.plist"
      
    4. Build and Run the current scheme

提交回复
热议问题