[MBProgressHUD showMessage:KLoading toView:KWINDOW];
NSString*urlStr1=@"http://itunes.apple.com/cn/lookup?id=1406688801";
AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
[manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
manager.requestSerializer.timeoutInterval = 10;
[manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"application/json", @"text/html",@"text/json", @"text/javascript",@"text/plain", nil];
[manager GET:urlStr1 parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
// 传输进度
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject)
{
[MBProgressHUD hideHUDForView:KWINDOW animated:YES];
if (responseObject)
{
NSString*str=[[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
DLog(@"str----->>%@",str);
id responseObjectId=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
if ([responseObjectId[@"resultCount"] integerValue]==0)
{
[MBProgressHUD showSuccess:@"暂无更新"];
}
else
{
NSString *newVersion;
NSArray *array = responseObjectId[@"results"];
for (NSDictionary *dic in array)
{
newVersion = [dic valueForKey:@"version"];
}
//获取本地软件的版本号
NSString *localVersion = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSString *updateMsg = responseObjectId[@"results"][0][@"releaseNotes"];
//对比发现的新版本和本地的版本
if ([newVersion doubleValue] > [localVersion doubleValue])
{
MLLUpdateView*updateView=[[MLLUpdateView alloc]initWithFrame:self.view.bounds WithMessage:updateMsg withUrl:responseObjectId[@"results"][0][@"trackViewUrl"] isForce:NO];
[updateView showAlert];
}
else
{
[MBProgressHUD showSuccess:@"已是最新版本"];
}
}
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)
{
DLog(@"error-->%@",error);
[MBProgressHUD hideHUDForView:KWINDOW animated:YES];
[IanAlert alertWithTitle:@"当前网络不可用,请稍后再试" message:nil yes:@"好的" confirm:^{
}];
}];
网友评论