+ (void)checkAppStoreVersionCallBack:(void (^)(BOOL))callBack {
    NSString* strurl = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", @"1440104727"];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURL *url = [NSURL URLWithString:strurl];

    //2.创建可变的请求对象
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error){
        //4.解析数据
        NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
        NSArray * results = dict[@"results"];
        NSDictionary * dic = results.firstObject;
        NSString * lineVersion = dic[@"version"];//版本号
        NSString * releaseNotes = dic[@"releaseNotes"];//更新说明
        NSString * trackViewUrl = dic[@"trackViewUrl"];//链接
        NSLog(@"App store版本号:%@",lineVersion);
        NSLog(@"更新说明:%@",releaseNotes);
        NSLog(@"App下载链接:%@",trackViewUrl);

//        5、获取本地版本
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        // 本地app版本
        NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

//       6、比较版本信息
        if ([lineVersion floatValue] > [app_Version floatValue]) {
//            7、回到主线程进行后续操作
            dispatch_async(dispatch_get_main_queue(), ^{
//                    [self setGengxinUI];
                if (callBack) callBack(YES);
            });

            NSLog(@"^^%@",app_Version);
        }else{
//            7、回到主线程进行后续操作
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"已是最新版本");
            });

        }

    }];

    //3.执行任务
    [dataTask resume];
}

0 Comments latest

No comments.