-(void)reloadVersion{
////获取本地版本信息
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSArray * array1 = [app_Version componentsSeparatedByString:@"."];
NSInteger currentVersionInt = 0;
NSString * releaseNotes = @"更新";//更新说明
NSString *AppID =@"1468604217";
if (array1.count == 3)//默认版本号1.0.0类型
{
currentVersionInt = [array1[0] integerValue]*100 + [array1[1] integerValue]*10 + [array1[2] integerValue];
}
//获取后台版本信息
NSString *url = [NSString stringWithFormat:@"%@%@",Server,@"/app/version.json"];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"version%@ ---%@",app_Version, responseObject);
if ([[responseObject objectForKey:@"android_agent"] integerValue]>currentVersionInt) {
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"发现新版本"message:releaseNotes preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * ok = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction * update = [UIAlertAction actionWithTitle:@"去更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//跳转到App Store
NSString *urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8",AppID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
}];
[alert addAction:ok];
[alert addAction:update];
[[AppDelegate sharedAppDelegate].topViewController presentViewController:alert animated:YES completion:nil];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@",error);
}];
}
网友评论