参考文档:http://my.oschina.net/heweipo/blog/382942

IOS IPA文件中包含Info.plist文件,类似于Android的AndroidManifest.xml,因此想获取IOS版本相关信息,就需要解析其Info.plist文件。参考文档中有详细的描述,但编译不过,调用的函数名搞错了,以如下代码为准。

public class IpaUtil{/*** 解压IPA文件,只获取IPA文件的Info.plist文件存储指定位置* @param file   zip文件* @param unzipDirectory     解压到的目录* @throws Exception*/private static File getZipInfo(File file, String unzipDirectory) throws Exception{// 定义输入输出流对象InputStream input = null;OutputStream output = null;File result = null;File unzipFile = null;ZipFile zipFile = null;try{// 创建zip文件对象zipFile = new ZipFile(file);// 创建本zip文件解压目录String name = file.getName().substring(0, file.getName().lastIndexOf("."));unzipFile = new File(unzipDirectory + "/" + name);if(unzipFile.exists()){unzipFile.delete();}unzipFile.mkdir();// 得到zip文件条目枚举对象Enumeration<? extends ZipEntry> zipEnum = zipFile.entries();// 定义对象ZipEntry entry = null;String entryName = null;String names[] = null;int length;// 循环读取条目while(zipEnum.hasMoreElements()){// 得到当前条目entry = zipEnum.nextElement();entryName = new String(entry.getName());// 用/分隔条目名称names = entryName.split("\\/");length = names.length;for(int v = 0; v < length; v++){if(entryName.endsWith(".app/Info.plist")){ // 为Info.plist文件,则输出到文件input = zipFile.getInputStream(entry);result = new File(unzipFile.getAbsolutePath() + "/Info.plist");output = new FileOutputStream(result);byte[] buffer = new byte[1024 * 8];int readLen = 0;while((readLen = input.read(buffer, 0, 1024 * 8)) != -1){output.write(buffer, 0, readLen);}break;}}}}catch(Exception ex){ex.printStackTrace();}finally{if(input != null){input.close();}if(output != null){output.flush();output.close();}// 必须关流,否则文件无法删除if(zipFile != null){zipFile.close();}}// 如果有必要删除多余的文件if(file.exists()){file.delete();}return result;}/*** IPA文件的拷贝,把一个IPA文件复制为Zip文件,同时返回Info.plist文件 参数 oldfile 为 IPA文件*/private static File getIpaInfo(File oldfile) throws IOException{try{int byteread = 0;String filename = oldfile.getAbsolutePath().replaceAll(".ipa", ".zip");File newfile = new File(filename);if(oldfile.exists()){// 创建一个Zip文件InputStream inStream = new FileInputStream(oldfile);FileOutputStream fs = new FileOutputStream(newfile);byte[] buffer = new byte[1444];while((byteread = inStream.read(buffer)) != -1){fs.write(buffer, 0, byteread);}if(inStream != null){inStream.close();}if(fs != null){fs.close();}// 解析Zip文件return getZipInfo(newfile, newfile.getParent());}}catch(Exception e){e.printStackTrace();}return null;}/*** 通过IPA文件获取Info信息*/public static Map<String, String> getVersionInfo(File ipa) throws Exception{File file = getIpaInfo(ipa);Map<String,String> map = new HashMap<String,String>();// 需要第三方jar包dd-plist NSDictionary rootDict = (NSDictionary)PropertyListParser.parse(file); // 应用包名 NSString parameters = (NSString)rootDict.objectForKey("CFBundleIdentifier"); map.put("CFBundleIdentifier", parameters.toString()); // 应用名称 NSString parameters = (NSString)rootDict.objectForKey("CFBundleName");map.put("CFBundleName", parameters.toString());// 应用版本 parameters = (NSString)rootDict.objectForKey("CFBundleVersion");map.put("CFBundleVersion", parameters.toString());// 应用展示的名称 parameters = (NSString)rootDict.objectForKey("CFBundleDisplayName"); map.put("CFBundleDisplayName", parameters.toString()); // 应用所需IOS最低版本 parameters = (NSString)rootDict.objectForKey("MinimumOSVersion"); map.put("MinimumOSVersion", parameters.toString()); // 如果有必要,应该删除解压的结果文件file.delete(); file.getParentFile().delete(); return info; }
}

如果用Maven,可以在pom文件中加入如下xml,获取到第三方包dd-plist:

<dependency><groupId>com.googlecode.plist</groupId><artifactId>dd-plist</artifactId><version>1.16</version>
</dependency>

如果想直接获取到此jar包,可以在此处下载:http://download.csdn.net/detail/ruyi366/9149741

Java解析IOS IPA文件相关推荐

  1. IDEA Java解析GeoJson.json文件

    IDEA Java解析GeoJson.json文件 一.遇到的问题 1. 无法导入成功 2. org.geotools.StyleFactory is not an ImageIO SPI class ...

  2. 关于java解析bvh动作文件

    最近正在学习安卓openGL(其实各个平台相差不多),为了让人物模型上来自己动,而且不要动的那么露骨,我就在网上找现成的动作数据想将它绑定到模型对象上,搜了一下才发现原来这种数据有几种专门的文件格式来 ...

  3. java 解析ttf字体文件

    要了解ttf字体文件的原理更方便对代码的理解 package com.maoyan.movie.ttf.encode;public class PostTableHeader {public long ...

  4. java解析word2003 doc文件中的表格

    1:apache poi插件链接http://poi.apache.org/ 这个插件主要用于office文件文本内以及富文本(表格,图片)等的提取,还有支持对已知密码的office文件的提取, 其他 ...

  5. java解析sgf格式文件简单实现

    围棋棋谱一般被保存为sgf格式,要想在自己的网站中实现打谱功能,必要要会解析sgf文件,取出里面的对局信息和落子,楼主现在用一种比较简单的方法来解析它 说明:楼主所用的棋谱是从新浪围棋里下载来的,示例 ...

  6. java解析pdf格式文件获取文本内容

    思路:先将pdf按照页数分割成图片,在将分割的图片做图片识别,提取文字,最后将提取到的文字解析或者保存到txt文件. 图片识别我使用的是百度开发者中心提供的 图片识别接口,我在上一篇文章中有详细说明, ...

  7. java解析string_java读取文件内容为string字符串的方法

    直接就把项目中的方法贴出来吧 /** * 读出城市列表文件 */ private String readCityFile() { File file02 = new File(path_xinfu, ...

  8. 重新签名IOS .ipa文件 (包含第三方框架和插件)

    本文未经测试,初步看代码流程接近本人想法,留下作记录. Intoduction This code allow you to resign your own ipa assuming that you ...

  9. gradle文件利用java解析_使用文件读取Gradle Multi项目构建

    嗨,我有2个项目的文件如下: project1 \- build.gradle project2 \- build.gradle \- build.properties project1: build ...

最新文章

  1. 2010年南非世界杯乌拉圭和韩国八强赛观后感
  2. [云炬创业基础笔记]第九章企业的法律形态测试2
  3. python读取大文件的某行_Python按行读取文件的实现方法【小文件和大文件读取】...
  4. LeetCode 16 3Sum Closest(最接近的3个数的和)
  5. 为啥不用ActiveRecord
  6. SQL 字段保留下划线后部分
  7. 机器学习作业班_python实现逻辑回归多类分类
  8. C# ComBox 垂直滚动条
  9. java中try中的语句执行吗_Java异常try里面有return,finally代码会执行吗
  10. mysqladvisor安装
  11. 中国贸易外经统计年鉴(2021年)
  12. 2020、2021年FRM一级二级notes
  13. visual studio多工程项目管理
  14. 12.15 小程序验证码点击刷新
  15. Abaqus设置初始地应力场
  16. n元线性方程组解的情况及判别准则
  17. 工具应用——Chrome浏览器 F12控制台中文改成英文
  18. 如何让Word 2003识别Docx文件
  19. 四大维度,七大案例,300+测试问题,《腾讯手游测试实战手册》发布
  20. shell中test命令方法详解

热门文章

  1. NPOI复制Excel工作簿Sheet以及删除Excel工作簿
  2. Python(pyemd)
  3. 【没事才点】又有一个无聊的小游戏(防空炮)
  4. 命运战歌电脑版模拟器怎么玩
  5. HTML5编写抢高铁票,Python3实现抢火车票功能(中)
  6. ActiveStorage. 英文书Learnrails5.2的案例,看如何放到云上。
  7. 列举 3 种目前比较热的手机 APP,说明对应类别后并对其进行简要描述(提示:可从目标人群、主要功能特点、使用场合等多种角度进行描述)
  8. 一条咸鱼的java学习笔记第7天之Oracle数据库
  9. 基于SVM的近红外光谱建模
  10. Linux基本命令Linux基本命令