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连接外设的代码实现
上一篇文章介绍了蓝牙的技术知识,这里我们具体说明一下中心模式的应用场景.主设备(手机去扫描连接外设,发现外设服务和属性,操作服务和属性的应用.一般来说,外设(蓝牙设备,比如智能手环之类的东西), 会由 ...
随机推荐
- [转自小兵的工具箱]C++ Builder 基础
1. C++ Builder 网上资源 C++ Builder 研究 http://www.ccrun.com/ C++ Builder 程序员 http://mybcb.diy.myri ...
- java面试问道的
1.java可重入锁 2.Hashmap原理.说说hashMap是怎样实现的(这个之前看过,顺利回答上.还回答了多线程的问题出现的原因,面试官表示很惊讶的样.用hashmap实现hashset 3.
- Android Gradle 编译错误Java finished with non-zero exit value 2
出现这个错误主要有两类错误 依赖包重复 方法数超过65K 针对第一种错误,可能是由于build.gradle里写了 compile fileTree(dir: 'libs', include: ['* ...
- 新建android项目报错,代码中找不到错误
通过网上资料的引导,做以下操作: 1.进入C:\Documents and Settings\Administrator\.android 删除路径下的debug.keystore及 ddms.cfg ...
- Squid 操作实践
Squid简介 Squid可以做什么 性能要素 Squid安装 Squid快速体验 Squid配置 Squid简介 Squid is a caching proxy for the Web suppo ...
- java 开发, jdk 1.6 官方下载地址
在oracle官方网站默认下载的jdk是最新的,目前正式版是1.8. 但有些项目要求是1.6的jdk,费了九牛二虎之力终于找到了1.6的官方版本,链接如下: http://www.oracle.com ...
- 低功耗蓝牙4.0BLE编程-nrf51822开发(6)-Battery Service
Battery Service是有关电池特性方面的服务,如果需要它,在初始化时将它加入到蓝牙协议栈. 如果通过ble_bas_battery_level_update(),电池电量将会通知,Batte ...
- ThreadLocal知识总结
以前学习<Thinking in Java>时,了解过ThreadLocal,但没做笔记.现在又忘记了.嗯,要勤动笔.API中ThreadLocal的方法: public T get() ...
- php---分组函数group_concat()
group_concat()函数总结 group_concat(),手册上说明:该函数返回带有来自一个组的连接的非NULL值的字符串结果.比较抽象,难以理解. 通俗点理解,其实是这样的:group_c ...
- mysql integer size 大小
I was always wondering what the size of numeric columns in MySQL was. Forgive me if this is obvious ...