版本更新有兩種方式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的圖標這裏再也不寫了