IOS 获取App stroe 发布的版本
-(void)onCheckVersion{
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
NSString *URL = @"http://itunes.apple.com/lookup?id=你APP对应的ID";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:URL]];
[request setHTTPMethod:@"POST"];
NSHTTPURLResponse *urlResponse = nil;
NSError *error = nil;
NSData *recervedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:recervedData options:0 error:nil];
NSArray *infoArray = [dic objectForKey:@"results"];
if ([infoArray count]) {
NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
NSString *lastVersion = [releaseInfo objectForKey:@"version"];
if (![lastVersion isEqualToString:currentVersion]) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alert = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alertController addAction:alert];
[self presentViewController: alertController animated:YES completion:nil];
}
}
}
浙公网安备 33010602011771号