//获取手机程序的版本号
NSString *ver = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//获取网络该应用的版本号
AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
[mgr.responseSerializer setAcceptableContentTypes: [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil]];
//POST必须上传的字段
[mgr POST:@"https://itunes.apple.com/lookup?id=应用id" parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *array = responseObject[@"results"];
if (array.count != 0) {// 先判断返回的数据是否为空
NSDictionary *dict = [array lastObject];
//版本号的比较
NSString * str1 = dict[@"version"];
NSString * str2 = ver;
if ([str1 compare:str2 options:NSCaseInsensitiveSearch]>0)
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"发现新版本,立即去下载!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/us/app/v-kuai-di/id应用id?l=zh&ls=1&mt=8"]];
}];
[alertController addAction:confirm];
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
}
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];