iOS 在系统设置中展示Version, Build, Git等信息

Posted 伟大是熬出来的

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS 在系统设置中展示Version, Build, Git等信息相关的知识,希望对你有一定的参考价值。

 在设置中,展示自定义内容,如下图INFO区域内容:

       

步骤:

1.在项目中添加Settings.bundle文件

 

Root.plist和Root.plist的Source code如下:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>Title</key>
            <string>Info</string>
            <key>Type</key>
            <string>PSGroupSpecifier</string>
        </dict>
        <dict>
            <key>DefaultValue</key>
            <string>-</string>
            <key>Key</key>
            <string>version_preference</string>
            <key>Title</key>
            <string>Version</string>
            <key>Type</key>
            <string>PSTitleValueSpecifier</string>
        </dict>
        <dict>
            <key>DefaultValue</key>
            <string>-</string>
            <key>Key</key>
            <string>build_preference</string>
            <key>Title</key>
            <string>Build</string>
            <key>Type</key>
            <string>PSTitleValueSpecifier</string>
        </dict>
        <dict>
            <key>DefaultValue</key>
            <string>-</string>
            <key>Key</key>
            <string>githash_preference</string>
            <key>Title</key>
            <string>Git</string>
            <key>Type</key>
            <string>PSTitleValueSpecifier</string>
        </dict>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

 

3.编辑脚本,设置Settings.bundle的值

#获取Version
Version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:1:DefaultValue ${Version}" "${PROJECT_DIR}/${PROJECT_NAME}/Settings.bundle/Root.plist"

#获取Build
Build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:2:DefaultValue ${Build}" "${PROJECT_DIR}/${PROJECT_NAME}/Settings.bundle/Root.plist"

#获取Git当前git SHA1值
Git=`git rev-parse --short HEAD | awk \'{print $1}\'`
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:3:DefaultValue ${Git}" "${PROJECT_DIR}/${PROJECT_NAME}/Settings.bundle/Root.plist"

 

4.配置项目脚本
   路径: Target -> 项目名字 -> Build Phases

    1. 如果没有Run Script就在该区域左上角+来增加;
    2. 将步骤3的脚本复制粘贴即可。

ok! 完成!

 

另:
plist文件的Item主要有六种类型,分别是:Group、Multi Value、Slider、Text Field、Title、Switch;

Group代表分组样式。
Multi Value代表该项有子菜单可供选择。
Slider代表滑块效果。
Text Field输入框效果。
Title 显示标题。
Switch 显示开关。

 

如果想达到类似效果,只需参考上述类型并设置相关属性即可。

 

以上是关于iOS 在系统设置中展示Version, Build, Git等信息的主要内容,如果未能解决你的问题,请参考以下文章

maven-buildnumber-插件

编译报错Building for iOS, but the linked and embedded framework ‘xxx.framework’ was buil......

编译报错Building for iOS, but the linked and embedded framework ‘xxx.framework’ was buil......

编译报错Building for iOS, but the linked and embedded framework ‘xxx.framework’ was buil......

编译报错Building for iOS, but the linked and embedded framework ‘xxx.framework’ was buil......

IOS将字典存入plist 文件中时,怎么设置字典名