ios 关于如何在app里面设置版本更新功能

摘要:
#import“ViewController.h”@interfaceViewController()@end@implementationViewController-(void)viewDidLoad{[superviewDidLoad];self.title=@“版本检测更新”;self.view.backgroundColor=[UIClorwhiteColor];[selfcheckV
#import "ViewController.h"

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"版本检测更新";
    self.view.backgroundColor = [UIColor whiteColor];
    [self checkVersion];   //检测升级  
}

-(void)checkVersion
{
    NSString *newVersion;
    NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/cn/lookup?id=1139094792"];//这个URL地址是该app在iTunes connect里面的相关配置信息。其中id是该app在app store唯一的ID编号。
    NSString *jsonResponseString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"通过appStore获取的数据信息:%@",jsonResponseString);
    
    NSData *data = [jsonResponseString dataUsingEncoding:NSUTF8StringEncoding];
//    解析json数据
    id json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    NSArray *array = json[@"results"];
    for (NSDictionary *dic in array) {
        newVersion = [dic valueForKey:@"version"];
    }
    
    NSLog(@"通过appStore获取的版本号是:%@",newVersion);
    //获取本地软件的版本号
    NSString *localVersion = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleVersion"];
    NSString *msg = [NSString stringWithFormat:@"你当前的版本是V%@,发现新版本V%@,是否下载新版本?",localVersion,newVersion];
    //对比发现的新版本和本地的版本
    if ([newVersion floatValue] > [localVersion floatValue])
    {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"升级提示"message:msg preferredStyle:UIAlertControllerStyleAlert]; 
        [self presentViewController:alert animated:YES completion:nil];
       
        [alert addAction:[UIAlertAction actionWithTitle:@"现在升级" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/yi-ka-tongbic-ban/id1139094792?l=en&mt=8"]];这里写的URL地址是该app在app store里面的下载链接地址,其中ID是该app在app store对应的唯一的ID编号。
            NSLog(@"点击现在升级按钮");
        }]];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"下次再说" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"点击下次再说按钮");
        }]];
    }
}

免责声明:文章转载自《ios 关于如何在app里面设置版本更新功能》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇FreeSql取多表数据内存泄漏(memory leak)和内存溢出下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Ubuntu 字体安装

命令安装:           以微软雅黑字体为例(其他的宋体、黑体等点阵字体都一样的),我们的雅黑字体文件是:Yahei.ttf(放在自己的主目录下)(在widows目录的Fonts目录下找需要的字体)由于我是双系统,我直接从Win7中复制了 msyh.ttf和msyhbd.ttf 到Ubuntu下 1在/usr/share/fonts/下新建文件夹 如...

windows 和office破解

office 365、2016、2019专业版、批量版或零售版都可以的,不需要密钥快速激活。 这样的软件: 1、激活成功率非常高同时激活速度非常快,几乎支持所有Vl批量授权版本的产品; 2、对于软件没有直接支持的产品你还可以通过搭建内置的KMS服务器然后进行手动激活产品; 3、支持对Windows系统以及Office办公软件备份激活信息,重装系统或软件可以...

用组策略彻底禁止USB存储设备、光驱、软驱、ZIP软驱

转自:http://beyondhdf.blog.51cto.com/229452/131678 一、禁止USB存储设备、光驱、软驱、ZIP软驱 在现在企业网络环境下,由于企业网络越来越大环境越来越复杂。公司内员工素质参差不齐,公司为了加强网络安全性、数据保密性提出要封堵USB存储设备、光驱、软驱、ZIP软驱设备。首先我们在企业网络环境要想实现以上目的,必...

安卓app设计规范整理和Android APP设计篇(转)

随着安卓智能手机不停的更新换代。安卓手机系统越来越完美,屏幕尺寸也越来越大啦!比如最近小米的miui 6的发布和魅族手机系统的更新等等。 以小米MIUI6的安卓手机来说,MIUI6进行了全新设计,坚持“内容才是本质”的设计哲学,重新提炼内容,简化图标设计。 所以,我们在进行安卓APP设计时,需要好好调整之前的设计规范和设计细节。根据目前流行的安卓手机的系...

一、Linux 安装

Linux 安装本章节我们将为大家介绍Linux的安装。 本章节以 centos6.4 为例。 centos 下载地址: 可以去官网下载最新版本:https://www.centos.org/download/ 以下针对各个版本的ISO镜像文件,进行一一说明: CentOS-7.0-x86_64-DVD-1503-01.iso : 标准安装版,一般下...

微信app支付,完整流程,完整代码 (转)

微信app支付流程 需要的配置参数 private function wechat($body,$indent_id,$cou,$user_id,$total_fee,$ip,$domain,$nonce_str){ //微信配置信息和初始逻辑 $appid= WxPayConfig::APPID; //appid (微信开放平台的应用appid) $bo...