iOS 检查版本号的代码
- (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 检查版本号的代码的更多相关文章
- iOS书摘之编写高质量iOS与OS X代码的52个有效方法
来自<Effective Objective-C 2.0编写高质量iOS与OS X代码的52个有效方法>一书的摘要总结 一.熟悉Objective-C 了解Objective-C语言的起源 ...
- iOS如何上传代码到Github
iOS如何上传代码到Github 很多iOS开发者想开源自己的代码或者demo,开源到Github是个不错的选择,那么如何上传我们的代码到Github,令所有人可以下载使用呢?这里我们的目的很明确,就 ...
- iOS 检查指定日期是否在当前日期之前
iOS检查指定日期是否在当前日期之前, 直接上代码: - (BOOL)checkProductDate: (NSString *)tempDate { NSDateFormatter *dateFor ...
- ios蓝牙开发(三)ios连接外设的代码实现:手机app去读写蓝牙设备。
手机app去读写蓝牙设备....... 代码下载: 原文博客主提供Github代码连接,地址是:https://github.com/coolnameismy/demo ios连接外设的代码实现流程: ...
- iOS 蓝牙开发(二)iOS 连接外设的代码实现(转)
转载自:http://www.cocoachina.com/ios/20150917/13456.html 原文作者:刘彦玮 上一篇文章介 绍了蓝牙的技术知识,这里我们具体说明一下中心模式的应用场景. ...
- iOS开发关于Block代码错误
本文永久地址为http://www.cnblogs.com/ChenYilong/p/4052362.html ,转载请注明出处. iOS开发关于Block代码错误 Incompatible bloc ...
- iOS_SN_BlueTooth (二)iOS 连接外设的代码实现
原文:http://www.cocoachina.com/ios/20150917/13456.html?utm_source=tuicool&utm_medium=referral 上一篇文 ...
- 【好程序员笔记分享】——iOS开发之纯代码键盘退出
-iOS培训,iOS学习-------型技术博客.期待与您交流!------------ iOS开发之纯代码键盘退出(非常简单) iOS开发之纯代码键盘退出 前面说到了好几次关于键盘退出的,但 ...
- ios蓝牙开发(二)ios连接外设的代码实现
上一篇文章介绍了蓝牙的技术知识,这里我们具体说明一下中心模式的应用场景.主设备(手机去扫描连接外设,发现外设服务和属性,操作服务和属性的应用.一般来说,外设(蓝牙设备,比如智能手环之类的东西), 会由 ...
随机推荐
- JS中基本window对象操作
---恢复内容开始--- 一.使用window中的属性时 window.属性,直接跟属性名.而调用window的函数时 window.hanshu(): 要在其函数名后面加括号. 二.windo ...
- 单片机与嵌入式 以及ARM DSP FPGA 几个概念的理解
嵌入式设备一般要满足实时性的要求,而实时性是要求数据输入和输出的延时满足一定的要求.当然嵌入式一般都便携性都比PC要好,功能没有PC多,PC是通用,他是专用,一般只专注某些功能的实现,比如DSP专注数 ...
- NRF51822之GPIOTE介绍
Note This library is obsolete and should not be used in new designs. Instead, you should use GPIOTE ...
- python中的类,对象,方法,属性等介绍
注:这篇文章写得很好.加底纹的是我自己的理解 python中一切皆为对象,所谓对象:我自己就是一个对象,我玩的电脑就是对象,坐着的椅子就是对象,家里养的小狗也是一个对象...... 我们通过描述属性( ...
- angularJS自定义属性作为条件中转
<html> <head> <meta charset="utf-8"/> <title></title> </h ...
- 设计模式:适配器模式(Adapter)
定 义:将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 有些国家用110V电压,而我们国家用的是220V,但是我们的电器,比 ...
- [LeetCode] Regular Expression Matching(递归)
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- 5分钟弄懂Docker!
http://www.csdn.net/article/2014-07-02/2820497-what%27s-docker 关注点:1.DOCKER和VM的架构区别 2.Docker 的容器利用了 ...
- [转载]浅谈C/C++内存泄漏及其检测工具
http://dev.yesky.com/147/2356147_3.shtml 对于一个c/c++程序员来说,内存泄漏是一个常见的也是令人头疼的问题.已经有许多技术被研究出来以应对这个问题,比如Sm ...
- 最流行的PHP 代码规范
“PHP是最好的编程语言” ;-) 那么PHPer习惯使用什么样的代码规范呢?sideeffect.kr通过分析GitHub上托管的开源代码,得出了一些有趣的结果,让我们一起来看看吧. 缩进 空格(7 ...