//版本检测
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=1602294206"];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:15];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
// //初始化提示框;
// UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请链接网络" preferredStyle: UIAlertControllerStyleAlert];
// [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// }]];
// //弹出提示框;
// [self presentViewController:alert animated:true completion:nil];
return ;
}
id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSLog(@"-----%@",obj);
NSArray *infoArray = [obj objectForKey:@"results"];
if ([infoArray count]) {
NSDictionary *relaseInfo = [infoArray objectAtIndex:0];
NSString *lastVersion = [relaseInfo objectForKey:@"version"];
NSString *urlstr = [relaseInfo objectForKey:@"trackViewUrl"];
if (![lastVersion isEqualToString:currentVersion]) {
//初始化提示框;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"检测到新版本" preferredStyle: UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"立即更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *url = [NSURL URLWithString:urlstr];
[[UIApplication sharedApplication]openURL:url];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"稍后提醒" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
//弹出提示框;
[self presentViewController:alert animated:true completion:nil];
}
}
}];
[task resume];