版本更新有两种方式web
一种是从服务器得到最新的版本信息和当前app的版本进行比较json
另一种是得到appStore上最新的版本信息和当前的app的版本进行比较api
如今我来讲一下如何经过appStore得到最新的版本(参考下面的苹果的官方文档)服务器
https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/app
以得到QQ的版本信息为例子:能够得到QQ的图标,版本号和bundleIDurl
打开这个连接spa
http://itunes.apple.com/search?term=QQ&country=CN&entity= iPadSoftwarecode
term:表明app的名称orm
country:表明国家blog
entity:表明类型可选得有software, iPadSoftware, macSoftware,不说你们也明白
这个链接打开之后会得到一个JS的文件,内容是json格式的长这个样子
解析json文件得到app的信息
下面直接上代码
NSString *appName = @"QQ"; // @"app的名称" NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/search?term=%@&country=CN&entity=software", appName]; NSURL *url = [NSURL URLWithString:urlStr]; NSData *json = [NSData dataWithContentsOfURL:url]; NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:json options:0 error:NULL];//解析json文件 NSArray *results = [dict objectForKey:@"results"]; NSDictionary *result = [results objectAtIndex:0]; NSString *versionStr = [result objectForKey:@"version"];//得到app的版本 self.version.text = versionStr; NSString * bundle = [result objectForKey:@"bundleId"];//得到app的id self.bundle.text = bundle;
根据字段:artworkUrl100还能得到app的图标这里再也不写了