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

前端 未结 13 789
一个人的身影
一个人的身影 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:50

    Based on @Quinn's answer, here the full process and working code I use to do this.

    • Add a settings bundle to your app. Don't rename it.
    • Open Settings.bundle/Root.plist in a text editor

    Replace the contents with:

    
    
    
    
        PreferenceSpecifiers
        
            
                Title
                About
                Type
                PSGroupSpecifier
            
            
                DefaultValue
                DummyVersion
                Key
                version_preference
                Title
                Version
                Type
                PSTitleValueSpecifier
            
        
        StringsTable
        Root
    
    
    
    • Create a Run Script build phase, move to be after the Copy Bundle Resources phase. Add this code:

      cd "${BUILT_PRODUCTS_DIR}"
      buildVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_PATH}" )
      /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $buildVersion" "${WRAPPER_NAME}/Settings.bundle/Root.plist"
      
    • Replace MyAppName with your actual app's name, and the 1 after PreferenceSpecifiers to be the index of your Version entry in the Settings. The above Root.plist example has it at index 1.

提交回复
热议问题