- (void)versionUpdate{

    //获得当前发布的版本
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ), ^{ //耗时的操作--获取某个应用在AppStore上的信息,更改id就行
__weak LoginViewController *weakSelf = self;
NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://itunes.apple.com/cn/lookup?id=1108288793"] encoding:NSUTF8StringEncoding error:nil];
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSString *version = [[[dic objectForKey:@"results"]firstObject]objectForKey:@"version"]; NSString *updateInfo = [[[dic objectForKey:@"results"]firstObject]objectForKey:@"releaseNotes"];
//NSString *updateURL = [[[dic valueForKey:@"results"] firstObject] objectForKey:@""]; //获得当前版本
NSString *currentVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"]; dispatch_async(dispatch_get_main_queue(), ^{
//更新界面
if ( version &&![version isEqualToString:currentVersion]) {
//有新版本
NSString *message = [NSString stringWithFormat:@"有新版本发布啦!\n%@",updateInfo];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"忽略" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"前往更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *url = @"https://itunes.apple.com/cn/app/rich-products/id1108288793?mt=8&uo=4"; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}]; [alertController addAction:action1];
[alertController addAction:action2]; [weakSelf presentViewController:alertController animated:YES completion:nil];
}else{
//已是最高版本
NSLog(@"已是最高版本");
} }); }); }

记得http://itunes.apple.com/cn/lookup?id=1108288793,这中间的这个CN不能掉了,不然返回的JSON数组为空。

iOS添加自动更新的代码的更多相关文章

  1. 后盾网lavarel视频项目---phpstorm 配置ftp, 自动更新同步代码

    后盾网lavarel视频项目---phpstorm 配置ftp, 自动更新同步代码 一.总结 一句话总结: 1.在phpstorm中设置:路径Tools/Deployment/Configuratio ...

  2. iOS 关于自动更新的分阶段发布(灰度发布)的相关简介

    前言:  AppStore 发布应用方式除了自动和手动,如今添加了分阶段发布(灰度发布).目的很明确,降低新版本骤然上升的bug率,不能挽回,只能发布新版本的风险.也也是针对禁止使用热修复,推出的相对 ...

  3. Git github webhook 自动更新/部署代码 php自动更新脚本

    这几天尝试了利用github的webhook,当代码更新到github,我们的测试服务器自动更新最新的gitbub仓库代码. 先列几个大概步骤,有时间再补充详细 1 . 服务器生成ssh key,一般 ...

  4. svn自动更新网站代码

    运行环境说明:svn的执行目录: /usr/bin/svnsvn版本库目录: /usr/local/nginx/html/svnrepos/coinhello (其中svnrepos是我各个项目版本库 ...

  5. 如何屏蔽 iOS 软件自动更新,去除更新通知和标记

    适用于 iOS.iPadOS 和 watchOS,即 iPhone.iPad 和 Apple Watch 通用. 请访问原文链接:https://sysin.org/article/Disable-i ...

  6. 关闭iOS的自动更新

    Safari打开网址https://oldcat.me/web/NOOTA9.mobileconfig,安装描述文件,就不会自动下载和提示更新最新的iOS了

  7. ios关闭自动更新

    iPhone系统更新超级烦人,避免测试机升级的方法 1. 设置禁用网络 设置-网线局域网-使用WLAN与蜂窝移动网的应用,将设置项设置为关闭 2. 一劳永逸,安装证书, 证书https://oldca ...

  8. git自动更新网站代码

    1.实现过程在linux上安装git服务.创建源版本库.从源版本库克隆得到网站目录,然后利用git中的hooks机制,在git push推送代码到源版本库的时候,触发编写的shell脚本,更新网站目录 ...

  9. springboot项目自动更新修改代码工具

    在pom.xml配置文件加入以下依赖,代码修改就不需要重启了. <dependency> <groupId>org.springframework.boot</group ...

随机推荐

  1. PHP IDE phpstorm 常用快捷键

    PHP IDE phpstorm 常用快捷键 投稿:junjie 字体:[增加 减小] 类型:转载   这篇文章主要介绍了PHP IDE phpstorm 常用快捷键,本文分别列出了mac系统和Win ...

  2. Xamarin学习资源收集

    推荐入门视频 跨行動平台App開發概觀- 使用Xamarin+Visual Studio https://www.youtube.com/watch?v=ELuFTTn1gS4 中文产品介绍http: ...

  3. Scrapy安装介绍

    一. Scrapy简介 Scrapy is a fast high-level screen scraping and web crawling framework, used to crawl we ...

  4. href="#"和javasrcript:void(0)的区别

    当我们需要一个空链接时,通常有两种方法: <a href="#">这个一个空链接</a> 和 <a href="javascript:voi ...

  5. 最有用的Linux命令行使用技巧集锦

    最近在Quora上看到一个问答题目,关于在高效率Linux用户节省时间Tips.将该题目的回答进行学习总结,加上自己的一些经验,记录如下,方便自己和大家参考. 下面介绍的都是一些命令行工具,这些工具在 ...

  6. JS面相对象

    一.理解对象: //第一种:基于Object对象 var person = new Object(); person.name = 'My Name'; person.age = ; person.g ...

  7. pro5

    1.本次课学到的知识点 (1)循环结构的概念 在我们需要重复进行某个步骤是就需要运用到循环结构. (2)三种循环语句 for,while,do-while是三种常用的循环语句,其中while的适用范围 ...

  8. 通过宏定义判断是否引入的是framework,反之则使用双引号,实用!

    例: #if __has_include(<TestHead/TestHead.h>) #import <TestHead/TestHead.h>#else#import &q ...

  9. Reactor 与 Proactor

    一.五种IO Model blocking IO nonblocking IO IO multiplexing signal driven IO(不常用) asynchronous IO 对于一个ne ...

  10. qt cef嵌入web

    原文http://blog.sina.com.cn/s/blog_9e59cf590102vnfc.html 最近项目需要,研究了下libcef库. Cef(Chromium Embedded Fra ...