- (void)checkNewVersion{

if ([@"appStore" isEqualToString:CHANNEL]) {

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

NSString *url = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", APPLE_ID];

[manager POST:url sign:nil token:self.user.token parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

id obj = [responseObject objectForKey:@"results"];

if (obj && [obj isKindOfClass:[NSArray class]]) {

versionResult = [obj lastObject];    //NSMutableDictionary     *versionResult;

if ([versionResult isKindOfClass:[NSMutableDictionary class]]) {//versionResult是全局的

NSString *newVersion = [versionResult objectForKey:@"version"];//appstore的版本

NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];

NSString *currentVersion = [infoDict objectForKey:@"CFBundleVersion"];//本地软件版本

if (newVersion && [currentVersion compare:newVersion] == NSOrderedAscending) {

UIAlertView *newVersionAlert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"检测到可用的新版本%@",newVersion]

message:[NSString stringWithFormat:@"%@",[versionResult objectForKey:@"releaseNotes"]]

delegate:self

cancelButtonTitle:@"稍后再说"

otherButtonTitles:@"马上升级",nil];

newVersionAlert.tag = NEW_VERSION_ALERT;//用于标记当前alert

[newVersionAlert show];

}

}

}

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

NSLog(@"Error: %@", error);

}];

} else {

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

NSString *url = CHECK_VERSION_URL;

[manager POST:url sign:nil token:self.user.token parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSString *newVersion = [responseObject objectForKey:@"vcode"];

NSString *newDesc = [responseObject objectForKey:@"vdesc"];

NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];

NSString *currentVersion = [infoDict objectForKey:@"CFBundleVersion"];//本地软件版本

if (newVersion && [currentVersion compare:newVersion] == NSOrderedAscending) {

UIAlertView *newVersionAlert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"检测到可用的新版本%@",newVersion]

message:newDesc

delegate:self

cancelButtonTitle:@"稍后再说"

otherButtonTitles:@"马上升级",nil];

newVersionAlert.tag = NEW_VERSION_ALERT;//用于标记当前alert

[newVersionAlert show];

}

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

NSLog(@"Error: %@", error);

}];

}

}

//点击马上升级的代理

#pragma mark UIAlertView Delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

[super alertView:alertView clickedButtonAtIndex:buttonIndex];

if (alertView.tag == NEW_VERSION_ALERT) {

//新版本提示框

if (buttonIndex == 1) {

if ([@"appStore" isEqualToString:CHANNEL]) {

//跳转到App Store

if ([versionResult isKindOfClass:[NSMutableDictionary class]]) {

UIApplication *application = [UIApplication sharedApplication];

NSString *trackViewUrl = [versionResult objectForKey:@"trackViewUrl"];

[application openURL:[NSURL URLWithString:[trackViewUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

}

} else {

UIApplication *application = [UIApplication sharedApplication];

NSString *trackViewUrl = APP_DOWNLOAD_URL;

[application openURL:[NSURL URLWithString:[trackViewUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

}

}

}

}

//黄色标记的为,#define得到的

如果需要检查版本的话,可直接复制一下代码,其中再大致修改一下

iOS 检查版本号的代码的更多相关文章

  1. iOS书摘之编写高质量iOS与OS X代码的52个有效方法

    来自<Effective Objective-C 2.0编写高质量iOS与OS X代码的52个有效方法>一书的摘要总结 一.熟悉Objective-C 了解Objective-C语言的起源 ...

  2. iOS如何上传代码到Github

    iOS如何上传代码到Github 很多iOS开发者想开源自己的代码或者demo,开源到Github是个不错的选择,那么如何上传我们的代码到Github,令所有人可以下载使用呢?这里我们的目的很明确,就 ...

  3. iOS 检查指定日期是否在当前日期之前

    iOS检查指定日期是否在当前日期之前, 直接上代码: - (BOOL)checkProductDate: (NSString *)tempDate { NSDateFormatter *dateFor ...

  4. ios蓝牙开发(三)ios连接外设的代码实现:手机app去读写蓝牙设备。

    手机app去读写蓝牙设备....... 代码下载: 原文博客主提供Github代码连接,地址是:https://github.com/coolnameismy/demo ios连接外设的代码实现流程: ...

  5. iOS 蓝牙开发(二)iOS 连接外设的代码实现(转)

    转载自:http://www.cocoachina.com/ios/20150917/13456.html 原文作者:刘彦玮 上一篇文章介 绍了蓝牙的技术知识,这里我们具体说明一下中心模式的应用场景. ...

  6. iOS开发关于Block代码错误

    本文永久地址为http://www.cnblogs.com/ChenYilong/p/4052362.html ,转载请注明出处. iOS开发关于Block代码错误 Incompatible bloc ...

  7. iOS_SN_BlueTooth (二)iOS 连接外设的代码实现

    原文:http://www.cocoachina.com/ios/20150917/13456.html?utm_source=tuicool&utm_medium=referral 上一篇文 ...

  8. 【好程序员笔记分享】——iOS开发之纯代码键盘退出

    -iOS培训,iOS学习-------型技术博客.期待与您交流!------------ iOS开发之纯代码键盘退出(非常简单)     iOS开发之纯代码键盘退出 前面说到了好几次关于键盘退出的,但 ...

  9. ios蓝牙开发(二)ios连接外设的代码实现

    上一篇文章介绍了蓝牙的技术知识,这里我们具体说明一下中心模式的应用场景.主设备(手机去扫描连接外设,发现外设服务和属性,操作服务和属性的应用.一般来说,外设(蓝牙设备,比如智能手环之类的东西), 会由 ...

随机推荐

  1. JBPM TaskInstance 对象创建过程

    对象获得过程如下: 获得对象工厂--->工厂创建代理对象 TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance(); TaskI ...

  2. base64coder调用

    base64coder 可以查看官网:   http://www.source-code.biz/base64coder/java/ 我所涉及到的  base64coder调用: 某天,因需要修改Pr ...

  3. https centos6 and 7

    keytool -printcert -sslserver 10.10.192.90:8443 -rfc >nexus.crt 通过  openssl 将 证书转换为 .pem格式的 通过以下命 ...

  4. windows2008一键安装环境的配置说明

    windows 2008 一键安装包下载地址为 http://gongdan.oss-cn-hangzhou.aliyuncs.com/market/cmISV/34320/product/cmgj0 ...

  5. Swift-09-可空链式调用(Optional Chaining)

    我对这个的理解就是:我们有可能会用到其他的属性或者方法,当我们在使用其他的时候,可以使用点语法去访问另一个的属性,这样的使用,就形成了链式访问. 可空链式调用是一种可以请求和调用属性.方法及下表的过程 ...

  6. fdisk 分区

    使用fdisk对SD卡进行从新分区.步骤如下: 1. 查看分区情况 ## sudo fdisk -l Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 h ...

  7. Interview Check If n Is A Perfect Square

    Check if a given number is a perfect square with only addition or substraction operation. eg. 25 ret ...

  8. 为什么一个object_id在dba_objects中为什么查不到记录?

    SQL> drop table test purge;SQL> create table test (id int,comments CLOB); SQL> select INDEX ...

  9. 6、JavaScript进阶篇③——浏览器对象、Dom对象

    一.浏览器对象 1. window对象 window对象是BOM的核心,window对象指当前的浏览器窗口. window对象方法: 注意:在JavaScript基础篇中,已讲解了部分属性,windo ...

  10. SQLdiag-配置文件-PerfmonCollector

    前一篇我们已经使用默认配置文件收集了部分诊断数据,并且知道配置文件会影响收集数据的内容.这一篇我们重点讲述配置文件中与性能计数器相关的操作.可使用XML模板控制SQLdiag使用的收集器.每个收集器可 ...