iOS Application Manifest.plist的创建与编辑
2014-02-25 15:46
411 查看
最近在做用JAVA后台分发Apple企业应用,使用XMLPropertyListConfiguration编辑Apple所用的plist文件,被其中的<array><array>标签搞得烦躁。
其中iOS应用的manifest.plist主要内容如下:
InstallApplicationContants.java
public enum InstallApplicationConstants {
Items("items"),
Assets("assets"),
KindPackage("kind"),
SoftwarePackage("software-package"),
Url("url"),
Metadata("metadata"),
BundleIdentifier("bundle-identifier"),
BundleVersion("bundle-version"),
Kind("kind"),
Software("software"),
Title("title"),
private String keyName;
private InstallApplicationConstants(String keyName) {
this.keyName = keyName;
}
public String getKeyName() {
return keyName;
}
}
大概思路就是先从最里面一层标签里开始用HashMap保存数组,如果需要<array>标签,也就还需要将这个HashMap放进ArrayList中并将这个list放入新的HashMap中,
最后通过plist.setProperty(".",topMap);把对象都放进plist中。(其中"."点表示plist根节点,大概是这个意思,这也是我遇到的问题所在,我一直不知道怎么把topMap这个对象用setProperty(key,value)放进plist中,直到后来突然觉得放个"."进去试试= =。)
其中topMap对象具体结构如下:
topMap is :{items=[{assets=[{url=https://xxx.ipa, kind=software-package}], metadata={bundle-identifier=packageName, title=appName, bundle-version=appVersion, kind=software}}]}
大括号{}对应plist中的<dict>字典标签,中括号[]对应<array>标签。
其中iOS应用的manifest.plist主要内容如下:
<?xml version="1.0"?> <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> <plist version="1.0"> <dict> <key>items</key> <array> <dict> <key>assets</key> <array> <dict> <key>url</key> <string>https://www.example.com/test.ipa</string> <key>kind</key> <string>software-package</string> </dict> </array> <key>metadata</key> <dict> <key>bundle-identifier</key> <string>packageName</string> <key>title</key> <string>appName</string> <key>bundle-version</key> <string>appVersion</string> <key>kind</key> <string>software</string> </dict> </dict> </array> </dict> </plist>要实现输出这么一张plist表,我采用了XMLPropertyListConfiguration类中提供的方法:具体代码如下:
private static String path = "/Users/hf/Documents/workspace/test/WebContent/WEB-INF/plist/manifest.xml"; public static void main(String[] args) { try { XMLPropertyListConfiguration plist; plist = new XMLPropertyListConfiguration(); HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> _map = new HashMap<>(); HashMap<String, Object> dataMap = new HashMap<>(); HashMap<String, Object> topMap = new HashMap<>(); ArrayList<Object> list = new ArrayList<>(); ArrayList<Object> topList = new ArrayList<>(); map.put(InstallApplicationConstants.KindPackage.getKeyName(), InstallApplicationConstants.SoftwarePackage.getKeyName()); map.put(InstallApplicationConstants.Url.getKeyName(), InstallApplicationConstants.IpaPostfix.getKeyName()); list.add(map); _map.put(InstallApplicationConstants.Assets.getKeyName(), list); // topList.add(_map); // plist.addProperty(InstallApplicationConstants.Items.getKeyName(), // _map); dataMap.put( InstallApplicationConstants.BundleIdentifier.getKeyName(), "packageName"); dataMap.put(InstallApplicationConstants.BundleVersion.getKeyName(), "appVersion"); dataMap.put(InstallApplicationConstants.Kind.getKeyName(), InstallApplicationConstants.Software.getKeyName()); dataMap.put(InstallApplicationConstants.Title.getKeyName(), "appName"); _map.put(InstallApplicationConstants.Metadata.getKeyName(), dataMap); // topList.add(_dataMap); // topMap.put(InstallApplicationConstants.Items.getKeyName(), // topList); topList.add(_map); topMap.put(InstallApplicationConstants.Items.getKeyName(), topList); System.out.println("topMap is :"+topMap.toString()); plist.setProperty(".", topMap); plist.save(path);//path 存储文件路径 } catch (ConfigurationException e) { System.out.println(e.toString()); } }
InstallApplicationContants.java
public enum InstallApplicationConstants {
Items("items"),
Assets("assets"),
KindPackage("kind"),
SoftwarePackage("software-package"),
Url("url"),
Metadata("metadata"),
BundleIdentifier("bundle-identifier"),
BundleVersion("bundle-version"),
Kind("kind"),
Software("software"),
Title("title"),
private String keyName;
private InstallApplicationConstants(String keyName) {
this.keyName = keyName;
}
public String getKeyName() {
return keyName;
}
}
大概思路就是先从最里面一层标签里开始用HashMap保存数组,如果需要<array>标签,也就还需要将这个HashMap放进ArrayList中并将这个list放入新的HashMap中,
最后通过plist.setProperty(".",topMap);把对象都放进plist中。(其中"."点表示plist根节点,大概是这个意思,这也是我遇到的问题所在,我一直不知道怎么把topMap这个对象用setProperty(key,value)放进plist中,直到后来突然觉得放个"."进去试试= =。)
其中topMap对象具体结构如下:
topMap is :{items=[{assets=[{url=https://xxx.ipa, kind=software-package}], metadata={bundle-identifier=packageName, title=appName, bundle-version=appVersion, kind=software}}]}
大括号{}对应plist中的<dict>字典标签,中括号[]对应<array>标签。
相关文章推荐
- 每天进步一点点——Swift项目实践
- iOS全局处理键盘事件
- Android 内存溢出解决方案(OOM) 整理总结
- ios之coredata
- android 数据库事务处理简单介绍
- Android View中 layout 的使用
- 在ios中使用FMDB
- (原)android修改文件所属的用户组
- 定位android kernel crash的方式
- YUV 420P IOS中的呈现
- 关于Android SDK无法更新的解决办法
- Android 微信分享遇到问题 及解决方案
- Android中线程通讯类Handler
- 应用netlink的内核模块和应用程序Makefile编写
- android ndk调试工具
- 关于Android SDK无法更新的解决办法
- android dolby
- Android NDK的入门学习过程(安装和helloJNI例程)
- AutoMapper在MVC中的运用01
- ios各种动画效果