2019-03-03

    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"];//链接

            //把版本号转换成数值

            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:@"发现新版本%@",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);

    }];

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 技术:有关maven学习 互联网运营:关于运营和做简历 一、有关Maven的学习: 1、有关maven包的下载:h...
    周家琪阅读 264评论 0 0
  • ####1.关于html标签 **在htm中这个元素是块级还是内联元素?(滚!我不管)[当你在写html标签时,不...
    追夢的蚂蚁阅读 248评论 0 0
  • 时间2016-11-23 09:35:54CocoaChina 原文http://www.cocoachina.c...
    Johnny_Chang阅读 656评论 0 5
  • AppDelegate.m #import "AppDelegate.h" #import "ViewContro...
    哈喽Mm阅读 364评论 0 0
  • 十一条鱼的故事 为什么治不好的病,我们没有学过医的人很轻易就能调好? 医生治不好的病,我们也...
    优优ljh阅读 310评论 0 0