博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS APP内弹窗推送版本更新信息(实现跳转、强制更新等)
阅读量:7129 次
发布时间:2019-06-28

本文共 3553 字,大约阅读时间需要 11 分钟。

项目必须要做这个,自己顺便记录一下

#pragma mark - 判断是否需要提示更新App- (void)updateVersion:(NSString *)path {    // 获取本地版本号    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];    // 取得AppStore信息    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];    manager.responseSerializer = [AFHTTPResponseSerializer serializer];    manager.requestSerializer = [AFJSONRequestSerializer serializer];    [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil]];        [manager GET:path parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {        NSLog(@"responseObject --- %@", responseObject);                NSData *dataCast = responseObject;        NSString *dataString = [[NSString alloc] initWithData:dataCast encoding:NSUTF8StringEncoding];        NSData *data =[dataString dataUsingEncoding:NSUTF8StringEncoding];        id json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];                NSArray *array = json[@"results"];                // app store 最新版本号        NSString *newVersion;        for (NSDictionary *dic in array) {            newVersion = [dic valueForKey:@"version"];        }                // 取更新日志信息        NSString *changeStr;        for (NSDictionary *dic in array) {            changeStr = [dic valueForKey:@"releaseNotes"];        }                // app store 跳转版本链接        NSString *trackViewUrl;        for (NSDictionary *dic in array) {            trackViewUrl = [dic valueForKey:@"trackViewUrl"];        }                NSLog(@"app store 的更新信息 --- %@, app store 的最新版本号 --- %@, 跳转版本链接 --- %@", changeStr, currentVersion, trackViewUrl);                NSInteger index = [self versionCompareFirst:newVersion andVersionSecond:currentVersion];                // AppStore版本号大于当前版本号,强制更新        if ([self versionCompareFirst:newVersion andVersionSecond:currentVersion] == 0) {            // 弹窗 更新            NSLog(@"");            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;            UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"发现新版本" message:[NSString stringWithFormat:@"新版本%@急需更新",newVersion] preferredStyle:UIAlertControllerStyleAlert];            UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"去更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {                NSLog(@"");                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:trackViewUrl]];            }];            [alertController addAction:sureAction];                        UIWindow   *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];            alertWindow.rootViewController = [[UIViewController alloc] init];            alertWindow.windowLevel = UIWindowLevelAlert + 1;            [alertWindow makeKeyAndVisible];            [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];                    } else {            // 正常进入程序            [self loadRootVC];        }                NSLog(@"");            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {        // 网络异常时,正常进入程序        NSLog(@"");        [self loadRootVC];    }];}复制代码

path为AppStore链接:http://itunes.apple.com/cn/lookup?id=(你的Apple ID)

啊啊啊以后不要再说为什么安卓可以实现,而iOS不可以

代码质量有点渣~大家见谅

转载于:https://juejin.im/post/5c3562a0f265da614d095c0d

你可能感兴趣的文章
透彻理解VLAN技术
查看>>
linux-Centos 7下bond与vlan技术的结合
查看>>
sqoop2安装配置
查看>>
ulimit调优|设置普通用户的ulimit值
查看>>
AGG第九课 agg::rendering_buffer 渲染缓存
查看>>
mysql5.6 的--dump-slave参数的用法
查看>>
rsync同步的实现及其简单源码包的编译安装
查看>>
AGG第三十八课 一些不常用的坐标转换管道
查看>>
实战案例:创建支持SSH服务的镜像
查看>>
Fiddler Web Debugger简单调试头部参数
查看>>
Linux环境下发布项目(Tomcat重新启动)
查看>>
centos7配置svn服务器
查看>>
亮剑:PHP,我的未来不是梦(13)
查看>>
MYSQL主从数据同步
查看>>
javascript数组操作
查看>>
linux中父进程退出时如何通知子进程
查看>>
linux 缩减文件系统大小 LVM
查看>>
对比文件md5值实现去重文件
查看>>
C#设计模式之二十三解释器模式(Interpreter Pattern)【行为型】
查看>>
js处理中文乱码记录/nodejs+express error 413
查看>>