-(void)appVersion{
//self.appUrlInAppStore为应用在AppStore的完整url地址
if (!self.appUrlInAppStore) {
return ;
}
NSURL *url = [NSURL URLWithString:self.appUrlInAppStore];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection connectionWithRequest:request delegate:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSError *error;
id response = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSDictionary *appInfo = (NSDictionary *)response;
NSArray *infoContent = appInfo[@"results"];
//最新版本号
NSString *newestVersion = [infoContent[0] objectForKey:@"version"];
NSLog(@"最新的版本号:%@",newestVersion);
//获取当前版本号
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentAppVersion = infoDic[@"CFBundleShortVersionString"];
NSLog(@"app现在的版本号:%@",currentAppVersion);
//根据两个版本号是不是一致去提示用户升级
}
转载于:https://my.oschina.net/u/2461772/blog/654277