Simple title output in ios settings bundle

后端 未结 6 1971
名媛妹妹
名媛妹妹 2021-02-01 21:17

I just want to output the version number of my ios application in a settings file.

I understand that I have to add the settings file to the application folder.

W

6条回答
  •  囚心锁ツ
    2021-02-01 21:59

    Another solution, without writing swift code is :

    1/ Create a Setting bundle

    This will create a new section for your app in the Settings of your device

    • Right click your project name -> New File -> Settings Bundle

    2/ Modify the Root.plist

    This will set what you want to display in your app settings - Inside your new Setting Bundle, right click on the Root.plist -> Open As -> Source Code

    • Copy Paste the Following code in it :

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

    3/ Create a Run Script

    This will always get the version of your app from the Info.plist and display it in your app Settings

    • Navigate to your Project Target on the left panel and click on Build Phases
    • Click the "+" button and hit "New Run Script Phase"
    • In the Newest Run Script section , Copy/Paste the following :

      #Getting Current Version
      VERSIONNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString"   "${PROJECT_DIR}/${INFOPLIST_FILE}")
      
      #Setting the version number in settings
      /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $VERSIONNUM" /Settings.bundle/Root.plist
      
    • Just replace YOUR-APP-NAME by your app name

提交回复
热议问题