- (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. 图算法(一)——基本图算法(BFS,DFS及其应用)(1)

    1)BFS 广度优先搜索:给定源节点s,生成广度优先搜索树广度优先搜索树中从节点s到节点v的简单路径对应的就是s到v的最短路径(边数最少的路径)广度优先:将已发现节点与未发现节点之间的边界(灰色节点) ...

  2. I方法 thinkphp

    function I($name,$default=null,$filter=null,$datas=null) { static $_PUT = null; $default_filter='htm ...

  3. iOS自定义控件开发详解

    http://blog.csdn.net/zhangao0086/article/details/45622875

  4. Qt拖拽界面 (*.ui) 缩放问题及解决办法(在最顶层放一个Layout)

    问题 使用Qt Designer 设计的界面,在缩放的时候不能随着主窗口一起缩放. 解决办法 之前遇到这个问题的时候,都是直接重写resizeEvent接口来实现的,在自动生成的Ui_Widget或U ...

  5. 【Android开发学习笔记】【第二课】Activity学习

    什么是Activity,就是我们所看到的 需要理解以下四句话: 1.一个Activity就是一个类,并且这个类需要集成Activity: 2.需要重写OnCreat方法 3.每个Activity都需要 ...

  6. One Time Auth

    One Time Auth One-time authentication (shortened as OTA) is a new experimental feature designed to i ...

  7. [LeetCode]题解(python):051-N-Queens

    题目来源 https://leetcode.com/problems/n-queens/ The n-queens puzzle is the problem of placing n queens ...

  8. 我的工具箱之Securecrt6.5.0

    Securecrt是一款支持SSH的终端仿真软件,一般用于连接Linux/Unix系统.感觉这个比Putty强些. 下载地址是:http://pan.baidu.com/s/1gednNhh

  9. python笔记 - day6

    python笔记 - day6 参考: http://www.cnblogs.com/wupeiqi/articles/5501365.html 大纲: 利用递归,实现阶乘: Python反射 pyt ...

  10. 关于js的call()和apply()两个函数的一点个人看法

    首先说明一下,call()和apply都是js的内置函数 它的作用是:改变call或者apply函数里面的``第一个参数对象``的指针,使它转向引用它的函数 call()的用法,call(对象,参数1 ...