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

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

    Based on the example here, here's the script I'm using to automatically update the settings bundle version number:

    #! /usr/bin/env python
    import os
    from AppKit import NSMutableDictionary
    
    settings_file_path = 'Settings.bundle/Root.plist' # the relative path from the project folder to your settings bundle
    settings_key = 'version_preference' # the key of your settings version
    
    # these are used for testing only
    info_path = '/Users/mrwalker/developer/My_App/Info.plist'
    settings_path = '/Users/mrwalker/developer/My_App/Settings.bundle/Root.plist'
    
    # these environment variables are set in the XCode build phase
    if 'PRODUCT_SETTINGS_PATH' in os.environ.keys():
        info_path = os.environ.get('PRODUCT_SETTINGS_PATH')
    
    if 'PROJECT_DIR' in os.environ.keys():
        settings_path = os.path.join(os.environ.get('PROJECT_DIR'), settings_file_path)
    
    # reading info.plist file
    project_plist = NSMutableDictionary.dictionaryWithContentsOfFile_(info_path)
    project_bundle_version = project_plist['CFBundleVersion']
    
    # print 'project_bundle_version: '+project_bundle_version
    
    # reading settings plist
    settings_plist = NSMutableDictionary.dictionaryWithContentsOfFile_(settings_path)
      for dictionary in settings_plist['PreferenceSpecifiers']:
        if 'Key' in dictionary and dictionary['Key'] == settings_key:
            dictionary['DefaultValue'] = project_bundle_version
    
    # print repr(settings_plist)
    settings_plist.writeToFile_atomically_(settings_path, True)
    

    Here's the Root.plist I've got in Settings.bundle:

    
    
    
    
        PreferenceSpecifiers
        
            
                Title
                About
                Type
                PSGroupSpecifier
            
            
                DefaultValue
                1.0.0.0
                Key
                version_preference
                Title
                Version
                Type
                PSTitleValueSpecifier
            
        
        StringsTable
        Root
    
    
    

提交回复
热议问题