和android的manifest.xml类似,ios中一个应用的版本信息,应用名称,兼容的最低版本等等都在ipa包中的info.plist中列出,但是对于一个打包好ipa包,里面的info.plist是乱码的,想要获取信息还是相当的麻烦。而最近也要到这方面的需求,找到的第一个方案是使用java调用linux 中的plutil工具来实现对info.plist的解析,这样做虽然可以实现但感觉太牵强了,,第二个方案是继续寻找纯java的解决方案,找啊找最后还是在老外的一个网站上(overstackflow.com)上找到有人提这样的问题,幸运的是还有很多哥们回复,老外果然是牛逼,最后照着做,可行了,具体的是找到了一个jar包,简单调用一下就Ok,先贴一下代码,对于怎样从ipa中提取info.plist就不罗嗦了,使用zip流就可以搞定,提供一个别人弄好的实现参考一下就ok(http://code.google.com/p/sunlab/source/detail?r=339):
import java.io.File; import com.dd.plist.PropertyListParser; public class Plist { public static void main(String[] args) throws Exception { File file = new File("d:\\angryInfo.plist"); File file1 = new File("d:\\angryInfo1.plist"); PropertyListParser.convertToXml(file, file1) ; //InputStream input = Plist.class.getClassLoader().getResourceAsStream(""); //NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(file); // // // // //String name = rootDict.objectForKey("Name").toString(); //NSObject[] parameters = ((NSArray) rootDict.objectForKey("Parameters")).getArray(); //for (NSObject param : parameters) { // //System.out.println(param.toXMLPropertyList()); // //if (param.getClass().equals(NSNumber.class)) { //NSNumber num = (NSNumber) param; //switch (num.type()) { //case NSNumber.BOOLEAN: { //boolean bool = num.boolValue(); ... //break; //} //case NSNumber.INTEGER: { //long l = num.longValue(); or int i = num.intValue(); ... //break; //} //case NSNumber.REAL: { //double d = num.doubleValue(); ... //break; //} //} //} else... //} } }