java解析ipa安装包生成plist文件并生成下载链接
发布日期:2021-10-12 17:51:38
浏览次数:2
分类:技术文章
本文共 4542 字,大约阅读时间需要 15 分钟。
项目说明及实现:
1、通过手机app发布平台发布app,上传app格式为ipa; 2、生成链接供苹果手机浏览器访问并下载安装app; 3、ipa格式app安装时,需要使用plist文件下载该app,并要遵循 itms-services协议; 4、生成一个html文件,用来指向plist文件;或后台重定向指向plist文件,由plist下载ipa文件。具体代码如下:
代码一:生成plist文件的方法public String createPlist(String fileName, String version) throws IOException { System.out.println("==========开始创建plist文件"); //plist和ipa文件在服务器中的路径,此处为window路径,linux路径有所差别 final String path = "D:\\project\\files\\"; String filePath = path + fileName; String plistFile = fileName+".plist"; String plistPath= path + plistFile; File file = new File(plistPath); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } String plist = " \n" + "\n" + "\n" + " "; try { FileOutputStream output = new FileOutputStream(file); OutputStreamWriter writer; writer = new OutputStreamWriter(output, "UTF-8"); writer.write(plist); writer.close(); output.close(); } catch (Exception e) { System.err.println("==========创建plist文件异常:" + e.getMessage()); } System.out.println("==========成功创建plist文件"); return plistFile; }\n" + " \n" + "items \n" + "\n" + " \n" + "\n" + " \n" + "assets \n" + "\n" + " \n" + "\n" + " \n" + "kind \n" + "software-package \n" + "url \n" //参数url配置ipa文件的下载路径,参数的值在下面一行设置 + ""+filePath+" \n" + "metadata \n" + "\n" + " \n" + "bundle-identifier \n" //参数bundle-identifier是开发者账号用户名,可以为空或任意,区别在于安装的过程中有无图标和进度,参数的值在下面一行设置 + "cn.vrv.im-inhouse \n" + "bundle-version \n" + "" + version + " \n" + "kind \n" + "software \n" + "subtitle \n" + "下载 \n" + "title \n" + "安装 \n" + "
代码二:生成html文件的方法,通过访问静态html的方式访问plist文件,再由plist自动下载ipa文件。除了使用静态html外也可以通过java后台重定向的方式下载ipa文件(查看代码三)。
public String createHtml(String plistPath) { System.out.println("==========开始创建html文件"); //plist和ipa文件在服务器中的路径,此处为window路径,linux路径有所差别 String path = "D:\\project\\files\\"; File file = new File(path); if (!file.exists()) { file.mkdirs(); } String plistFile = "a.plist"; final String plistPath = path + plistFile; file = new File(PLIST_PATH); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } String html = "\n" + "\n" + "\n" + " \n" + "下载 \n" + "\n" + "\n" + "\n" + ""; try { FileOutputStream output = new FileOutputStream(file); OutputStreamWriter writer = new OutputStreamWriter(output, "UTF-8"); writer.write(html); writer.close(); output.close(); } catch (IOException e) { System.err.println("==========创建html文件异常:" + e.getMessage()); } System.out.print("==========成功创建html文件"); return "success"; }
注意事项:
plist文件实际的下载路径如下:https://www.eric.com/download/xx.plist
这时,苹果手机的浏览器是无法下载的,需要在上面的下载路径前拼接字符串"itms-services://?action=download-manifest&url=",拼接后完整的访问路径如下:
itms-services://?action=download-manifest&url=https://www.eric.com/download/xx.plist
这时,再通过苹果手机的浏览器访问该路径就可以看到正常的下载安装界面了。
代码三:java后端controller层重定向访问plist下载ipa文件
@RequestMapping("/downloadIpa") public void downloadIpa(@RequestParam("filePath") String fileName, HttpServletRequest request, HttpServletResponse response) throws Exception{ String suffix = filePath.substring(fileName.lastIndexOf(".") + 1); if (suffix.equals("plist")) { response.sendRedirect("itms-services://?action=download-manifest&url=" + filePath); } }
注意:重定向路径前需要加上指定内容,具体原因看代码二中的注意事项。。
转载地址:https://blog.csdn.net/qq_39387856/article/details/86496927 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2024年04月26日 02时11分44秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
无法获取签名信息,请上传有效包(110506)
2019-04-28
【APICloud系列|10】最新苹果APP上架App Store流程(超详细)
2019-04-28
【APICloud系列|12】ios真机调试时如何添加新设备的udid?
2019-04-28
前端开发必备的1个CSS框架
2019-04-28
【APICloud系列|13】移动端适配通揽
2019-04-28
常用的视频下载网站
2019-04-28
问题:三元向量的比较
2019-04-28
C++ 在屏幕上用星号打印菱形
2019-04-28
使用微信开发者工具添加小程序底部导航栏报错
2019-04-28
Android killer软件闪退的解决办法?
2019-04-28
eclipse中在类saolei.Test 中找不到main方法
2019-04-28
安卓车机没有ADB调试,任意安装第三方软件教程
2019-04-28
某小型校园网规划与设计要点(课程报告)
2019-04-28
前端页面通过web3.eth.accounts无法获取账户信息
2019-04-28
解决 invalid input detected at ‘^’ marker的问题
2019-04-28
用C语言实现津巴布韦这道算法题?
2019-04-28
有什么好一点的方法读jdk源码吗?
2019-04-28
javaScript学习笔记之比较运算符||逻辑运算符||条件运算符(三目运算符)
2019-04-28
java学习笔记之条件语句(if...else)
2019-04-28