iOS Application Manifest.plist的创建与编辑

最近在做用JAVA后台分发Apple企业应用,使用XMLPropertyListConfiguration编辑Apple所用的plist文件,被其中的<array><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>标签。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值