在设置中,展示自定义内容,如类似下图圈住区域内容
步骤:
1.在项目中添加Settings.bundle文件
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>1.2.3</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>20170725.1</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>4993065</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
- 如果没有
Run Script
就在该区域左上角+
来增加; - 将步骤3的脚本复制粘贴即可。
ok! 完成!
时间: 2024-12-15 08:32:51