PlistBuddy中添加嵌套字段
PListBuddy
Info.plist是mac应用中的配置文件,官方定义是"属性列表是一种构建系统可以在运行时访问的任意数据的方法。信息属性列表是一种特殊类型的属性列表,其中包含包的配置数据。文件中的键和值描述了要应用于包的各种行为和配置选项."这边不作详细介绍(文末有apple官方文档链接),本文只针对Plist文件中添加嵌套字段的操作方法。
PlistBuddy的使用
PlistBuddy 是mac系统自带的plist文件编辑工具,PlistBuddy -help可查看帮助文档。plist文件中包含dict、array、string等类型。普通的添加字段在别的博文中都有过介绍,这里只分享在嵌套字段的添加:例如CFURLSchemes,它是放置在Array中的dict中的属性值.
具体属性的含义: https://www.cnblogs.com/xiao-love-meng/p/5896479.html
-
Info.plist 帮助
/usr/libexec/PlistBuddy -help
-
查看Info.plist
/usr/libexec/PlistBuddy -c "print" Info.plist
-
添加嵌套字段
/usr/libexec/PlistBuddy -c 'Add :CFBundleURLTypes Array ' $plistpath #增加CFBundleURLTypes数组
/usr/libexec/PlistBuddy -c 'Add :CFBundleURLTypes:0:CFBundleURLName string ' $plistpath #在item0增加string字段
/usr/libexec/PlistBuddy -c 'Add :CFBundleURLTypes:0:CFBundleURLSchemes Array ' $plistpath #在item 0增加Array字段
/usr/libexec/PlistBuddy -c 'Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string Appname' $plistpath #在嵌套array中添加值
- 删除
/usr/libexec/PlistBuddy -c 'Delete :CFBundleURLTypes' $plistpath