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连接外设的代码实现
上一篇文章介绍了蓝牙的技术知识,这里我们具体说明一下中心模式的应用场景.主设备(手机去扫描连接外设,发现外设服务和属性,操作服务和属性的应用.一般来说,外设(蓝牙设备,比如智能手环之类的东西), 会由 ...
随机推荐
- ubuntu12.04 安装 php5.4/php5.5
1:修改源(我使用163的源)直接修改/etc/apt/sources.list deb http://mirrors.163.com/ubuntu/ precise main universe re ...
- Bootstrap 巨幕页头缩略图和警告框组件
一.巨幕组件 //在固定的范围内,有圆角 <div class="container"> <div class="jumbotron"> ...
- yaf在windows7下32位的安装教程
首先下载php_yaf.dll文件http://pecl.php.net/package/yaf/2.2.9/windows 打开扩展extension=php_yaf.dll 然后下载工具 http ...
- 添加事件(jquery)
对盒子内部的盒子添加跟本身盒子相同的事件的时候,需要小心谨慎一点. 诸如: 从表象上看似乎没有什么太大问题,但是却存在一个致命的问题,就是每次点击box的时候,都会给test添加一个点击事件,而添加的 ...
- PHP---关联模型
MANY_TO_MANY
- Cygwin + CMake 测试
https://www.cygwin.com/ apt-get for cygwin? wget rawgit.com/transcode-open/apt-cyg/master/apt-cyg in ...
- Delphi FindowWindow,FindowWindowEx
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- Marshal.SecureStringToBSTR
Marshal.StringToBSTR 方法 命名空间:System.Runtime.InteropServices程序集:mscorlib(在 mscorlib.dll 中) // 使用一个Int ...
- Selenium2学习-015-WebUI自动化实战实例-013-通过 URL 关闭多余的已开浏览器窗口
在日常的 WebUI 自动化测试脚本执行的过程中,经常会打开不同的网页,进行相应的操作,此时可能会打开很多的网页,当打开的网页过多时,无效的网页资源对运行脚本的机器造成了过多无效的资源浪费,因而在日常 ...
- spring mvc 静态资源 404问题
spring mvc 静态资源 404问题 在web.xml配置servlet-mapping的时候,如果url-pattern设置为"/" (如下),很多人都会遇到导入js,cs ...