步骤1
id 指的是在你的应用在苹果商店中的id号 查看方法也简单:用电脑itunes打开,搜索自己的应用,然后复制网址,网址上有就是这个id号
NSURLRequest *rep = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://itunes.apple.com/lookup?id=1160672874"]];
[NSURLConnection connectionWithRequest:rep delegate:self];
步骤2
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSError *error;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSDictionary *appInfo = (NSDictionary*)jsonObject;
NSArray *infoContent = [appInfo objectForKey:@"results"];
NSString *version = [[infoContent objectAtIndex:0]objectForKey:@"version"];
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary]objectForKey:@"CFBundleShortVersionString"];
NSLog(@"商店的版本是%@ 当前的版本是%@",version,currentVersion);
if ([currentVersion doubleValue]<[version doubleValue]) {
NSLog(@"new:%@ old:%@",currentVersion,version);
UIAlertView *alerV = [[UIAlertView alloc]initWithTitle:@"发现新版本" message:@"App又添新功能啦,大量惊喜等您来发现" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:@"前往更新", nil];
[alerV show];
}
}