? ? NSString*appid =@"1450105728";
? ? NSString * url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",appid];//替換為自己App的ID
? ? // 獲取本地版本號
? ? NSString * currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
? ? // 網絡請求獲取最新版本
? ? [JWHttpRequest getWithStrPath:url withParameters:mdic withSuccess:^(id data) {
? ? ? ? NSArray* results = data[@"results"];
? ? ? ? if(results && results.count>0)
? ? ? ? {
? ? ? ? ? ? NSDictionary* dic = results.firstObject;
? ? ? ? ? ? NSString* lineVersion = dic[@"version"];//版本號
? ? ? ? ? ? NSString* releaseNotes = dic[@"releaseNotes"];//更新說明
? ? ? ? ? ? //NSString * trackViewUrl = dic[@"trackViewUrl"];//鏈接
? ? ? ? ? ? //把版本號轉換成數(shù)值
? ? ? ? ? ? NSArray* array1 = [currentVersioncomponentsSeparatedByString:@"."];
? ? ? ? ? ? NSIntegercurrentVersionInt =0;
? ? ? ? ? ? if(array1.count==3)//默認版本號1.0.0類型
? ? ? ? ? ? {
? ? ? ? ? ? ? ? currentVersionInt = [array1[0]integerValue]*100+ [array1[1]integerValue]*10+ [array1[2]integerValue];
? ? ? ? ? ? }
? ? ? ? ? ? NSArray* array2 = [lineVersioncomponentsSeparatedByString:@"."];
? ? ? ? ? ? NSIntegerlineVersionInt =0;
? ? ? ? ? ? if(array2.count==3)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? lineVersionInt = [array2[0]integerValue]*100+ [array2[1]integerValue]*10+ [array2[2]integerValue];
? ? ? ? ? ? }
? ? ? ? ? ? if(lineVersionInt > currentVersionInt)//線上版本大于本地版本
? ? ? ? ? ? {
? ? ? ? ? ? ? ? UIAlertController * alert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"發(fā)現(xiàn)新版本%@",lineVersion] 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]];
? ? ? ? ? ? ? ? }];
? ? ? ? ? ? ? ? [alertaddAction:ok];
? ? ? ? ? ? ? ? [alertaddAction:update];
? ? ? ? ? ? ? ? [selfpresentViewController:alert animated:YES completion:nil];
? ? ? ? ? ? }
? ? ? ? }
? ? }withFialure:^(NSError*error,NSString*status,NSString*message) {
? ? ? ? NSLog(@"版本更新出錯浦旱,%@",error.description);
? ? }];