Java: 生成plist文件

public boolean createPlist(String title, String path, String bundleId, String fileUrl, String versionCode) throws Exception {
        Log.info("开始创建plist文件");
        boolean success = true;
        File file = new File(path);
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                throw NetException.BusinessException("创建plist文件目录异常", e);
            }
        }
        String plist = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
                + "<plist version=\"1.0\">\n" + "<dict>\n"
                + "<key>items</key>\n"
                + "<array>\n"
                + "<dict>\n"
                + "<key>assets</key>\n"
                + "<array>\n"
                + "<dict>\n"
                + "<key>kind</key>\n"
                + "<string>software-package</string>\n"
                + "<key>url</key>\n"
                // 之前所上传的ipa文件路径(必须是https,否则无法下载!)
                + "<string>" + downloadUrlHost + fileUrl + "</string>\n"
                + "</dict>\n"
                + "</array>\n"
                + "<key>metadata</key>\n"
                + "<dict>\n"
                + "<key>bundle-identifier</key>\n"
                // 这个是开发者账号用户名,也可以为空,为空安装时看不到图标,完成之后可以看到
                + "<string>" + bundleId + "</string>\n"
                + "<key>bundle-version</key>\n"
                // 版本号
                + "<string>"+ versionCode +"</string>\n"
                + "<key>kind</key>\n"
                + "<string>software</string>\n"
                + "<key>subtitle</key>\n"
                + "<string>下载</string>\n"
                + "<key>title</key>\n"
                // 一定要有title,否则无法正常下载
                + "<string>"+ title +"</string>\n"
                + "</dict>\n"
                + "</dict>\n"
                + "</array>\n"
                + "</dict>\n"
                + "</plist>";
        try {
            FileOutputStream output = new FileOutputStream(file);
            OutputStreamWriter writer;
            writer = new OutputStreamWriter(output, "UTF-8");
            writer.write(plist);
            writer.close();
            output.close();
        } catch (Exception e) {
            throw NetException.BusinessException("创建plist文件异常", e);
        }
        Log.info("成功创建plist文件");
        return success;
    }
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值