1. 程式人生 > >Java: 生成plist檔案

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; }