//检查版本更新
+(void)checkVersion:(void(^)(NSString*isCurrentVersion))block
{
//appid 1150237660
AFHTTPSessionManager*manager =[AFHTTPSessionManager manager];
NSString*urlString =[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=1150237660"];
[manager POST:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
//最新版本
NSString*version =responseObject[@"results"][0][@"version"];
NSLog(@"AppStore最新版本:%@",version);
//当前版本
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
// 当前应用软件版本 比如:1.0.1
NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSLog(@"当前应用软件版本:%@",appCurVersion);
if([appCurVersion isEqualToString:version]){
//是最新版本
block(@"1");
}else{
//不是最新版本,回调最新版本号过去
block(version);
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
}];
}
//判断当前版本弹出提示框
[HttpsRequestManager checkVersion:^(NSString *isCurrentVersion) {
if ([isCurrentVersion isEqualToString:@"1"]) {
// TQ(@"提示", @"目前已经是最新版本", @"确定")
}else{
NSString*version =[NSString stringWithFormat:@"%@新版本来喽",isCurrentVersion];
UIAlertController*aaa =[UIAlertController alertControllerWithTitle:version message:@"火速一键升级至最新~" preferredStyle:UIAlertControllerStyleAlert];[aaa addAction:[UIAlertAction actionWithTitle:@"暂不下载" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {}]]; [aaa addAction:[UIAlertAction actionWithTitle:@"立即升级" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *str = [NSString stringWithFormat:
@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1150237660"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}]];[self presentViewController:aaa animated:YES completion:^{}];
}
}];