【ios】Settings 设置项

成果展示

 

 

1、创建Setttings.Bundle

 

2、修改Root.plist

<?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>DefaultValue</key>
			<string>1.0</string>
			<key>Key</key>
			<string>app_version</string>
			<key>Title</key>
			<string>版本</string>
			<key>Type</key>
			<string>PSTitleValueSpecifier</string>
		</dict>
		<dict>
			<key>Title</key>
			<string></string>
			<key>Type</key>
			<string>PSGroupSpecifier</string>
		</dict>
		<dict>
			<key>File</key>
			<string>UserProtocol</string>
			<key>Key</key>
			<string></string>
			<key>Title</key>
			<string>用户协议</string>
			<key>Type</key>
			<string>PSChildPaneSpecifier</string>
		</dict>
		<dict>
			<key>File</key>
			<string>PravacyProtocol</string>
			<key>Key</key>
			<string></string>
			<key>Title</key>
			<string>隐私协议</string>
			<key>Type</key>
			<string>PSChildPaneSpecifier</string>
		</dict>
	</array>
	<key>StringsTable</key>
	<string>Root</string>
</dict>
</plist>

  

3、创建Root.plist中的两个子面板中,file对应的plist文件:

UserProtocol.plist

<?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>New item</key>
	<string></string>
	<key>StringsTable</key>
	<string>Root</string>
	<key>PreferenceSpecifiers</key>
	<array>
        <dict>
            <key>Type</key>
            <string>PSGroupSpecifier</string>
            <key>Title</key>
            <string>用户啊用户</string>
        </dict>
	</array>
</dict>
</plist>

  

PravacyProtocol.plist

<?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>StringsTable</key>
    <string>Root</string>
    <key>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>Type</key>
            <string>PSGroupSpecifier</string>
            <key>Title</key>
            <string>隐私啊隐私</string>
        </dict>
    </array>
</dict>
</plist>

  

4、保证Root.plist   UserProtocol.plist   PravacyProtocol.plist 都在Settings.Bundle包中

 

 

5、脚本读取版本号

Build Phase,“+”icon

 

6、添加脚本

version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $SRCROOT/SLLiveChild/Info.plist`
/usr/libexec/PlistBuddy "$SRCROOT/SLLiveChild/Settings.bundle/Root.plist" -c "set PreferenceSpecifiers:0:DefaultValue $version"

  注释:

PreferenceSpecifiers:0:DefaultValue的意思是在PreferenceSpecifiers这个array下的第0个item的DefaultValue


最后
参考:

http://blog.rocketmade.com/post/60213039759/how-to-automatically-add-version-and-build-number

http://stackoverflow.com/questions/6851660/version-vs-build-in-xcode

 

posted @ 2016-05-11 10:45  kaysun5230  阅读(1504)  评论(0编辑  收藏  举报