iOS设备检查更新版本:

#pragma mark - 检查更新
- (void)checkUpdateWithAPPID:(NSString *)APPID
{
//获取当前应用版本号
NSDictionary *appInfo = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [appInfo objectForKey:@"CFBundleVersion"]; NSString *updateUrlString = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",APPID];
NSURL *updateUrl = [NSURL URLWithString:updateUrlString];
versionRequest = [ASIFormDataRequest requestWithURL:updateUrl];
[versionRequest setRequestMethod:@"GET"];
[versionRequest setTimeOutSeconds:60];
[versionRequest addRequestHeader:@"Content-Type" value:@"application/json"]; //loading view
CustomAlertView *checkingAlertView = [[CustomAlertView alloc] initWithFrame:NAVIGATION_FRAME style:CustomAlertViewStyleDefault noticeText:@"正在检查更新..."];
checkingAlertView.userInteractionEnabled = YES;
[self.navigationController.view addSubview:checkingAlertView];
[checkingAlertView release]; [versionRequest setCompletionBlock:^{ [checkingAlertView removeFromSuperview]; NSError *error = nil;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[versionRequest responseData] options:NSJSONReadingMutableContainers error:&error];
if (!error) {
if (dict != nil) {
// DLog(@"dict %@",dict);
int resultCount = [[dict objectForKey:@"resultCount"] integerValue];
if (resultCount == 1) {
NSArray *resultArray = [dict objectForKey:@"results"];
// DLog(@"version %@",[resultArray objectAtIndex:0]);
NSDictionary *resultDict = [resultArray objectAtIndex:0];
// DLog(@"version is %@",[resultDict objectForKey:@"version"]);
NSString *newVersion = [resultDict objectForKey:@"version"]; if ([newVersion doubleValue] > [currentVersion doubleValue]) {
NSString *msg = [NSString stringWithFormat:@"最新版本为%@,是否更新?",newVersion];
newVersionURlString = [[resultDict objectForKey:@"trackViewUrl"] copy];
DLog(@"newVersionUrl is %@",newVersionURlString);
// if ([newVersionURlString hasPrefix:@"https"]) {
// [newVersionURlString replaceCharactersInRange:NSMakeRange(0, 5) withString:@"itms-apps"];
// }
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"暂不" otherButtonTitles:@"立即更新", nil];
alertView.tag = 1000;
[alertView show];
[alertView release];
}else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您使用的是最新版本!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
alertView.tag = 1001;
[alertView show];
[alertView release];
}
}
}
}else
{
DLog("error is %@",[error debugDescription]);
}
}]; [versionRequest setFailedBlock:^{
[checkingAlertView removeFromSuperview]; CustomAlertView *alertView = [[CustomAlertView alloc] initWithFrame:NAVIGATION_FRAME style:CustomAlertViewStyleWarning noticeText:@"操作失败,请稍候再试!"];
[self.navigationController.view addSubview:alertView];
[alertView release];
[alertView selfRemoveFromSuperviewAfterSeconds:1.0];
}]; [versionRequest startSynchronous];
} - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
DLog(@"newVersionUrl is %@",newVersionURlString);
if (buttonIndex) {
if (alertView.tag == 1000) {
if(newVersionURlString)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:newVersionURlString]];
}
}
}
}

来源:http://blog.csdn.net/heartofthesea/article/details/14127587

iOS开发之检查更新的更多相关文章

  1. iOS开发之 几本书

    <object_c 编程之道书> <iOS 7 UI Transition Guide> iOS开发指南:从零基础到App Store上架[国内第一本iOS架构设计图书,涵盖i ...

  2. iOS开发系列--Swift语言

    概述 Swift是苹果2014年推出的全新的编程语言,它继承了C语言.ObjC的特性,且克服了C语言的兼容性问题.Swift发展过程中不仅保留了ObjC很多语法特性,它也借鉴了多种现代化语言的特点,在 ...

  3. iOS开发系列--打造自己的“美图秀秀”

    --绘图与滤镜全面解析 概述 在iOS中可以很容易的开发出绚丽的界面效果,一方面得益于成功系统的设计,另一方面得益于它强大的开发框架.今天我们将围绕iOS中两大图形.图像绘图框架进行介绍:Quartz ...

  4. iOS开发之再探多线程编程:Grand Central Dispatch详解

    Swift3.0相关代码已在github上更新.之前关于iOS开发多线程的内容发布过一篇博客,其中介绍了NSThread.操作队列以及GCD,介绍的不够深入.今天就以GCD为主题来全面的总结一下GCD ...

  5. 总结iOS开发中的断点续传那些事儿

    前言 断点续传概述 断点续传就是从文件赏赐中断的地方重新开始下载或者上传数据,而不是从头文件开始.当下载大文件的时候,如果没有实现断点续传功能,那么每次出现异常或者用户主动的暂停,都会从头下载,这样很 ...

  6. iOS开发系列文章(持续更新……)

    iOS开发系列的文章,内容循序渐进,包含C语言.ObjC.iOS开发以及日后要写的游戏开发和Swift编程几部分内容.文章会持续更新,希望大家多多关注,如果文章对你有帮助请点赞支持,多谢! 为了方便大 ...

  7. iOS开发系列--App扩展开发

    概述 从iOS 8 开始Apple引入了扩展(Extension)用于增强系统应用服务和应用之间的交互.它的出现让自定义键盘.系统分享集成等这些依靠系统服务的开发变成了可能.WWDC 2016上众多更 ...

  8. iOS开发系列--Swift进阶

    概述 上一篇文章<iOS开发系列--Swift语言>中对Swift的语法特点以及它和C.ObjC等其他语言的用法区别进行了介绍.当然,这只是Swift的入门基础,但是仅仅了解这些对于使用S ...

  9. iOS开发系列--通讯录、蓝牙、内购、GameCenter、iCloud、Passbook系统服务开发汇总

    --系统应用与系统服务 iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用 ...

随机推荐

  1. SVG中的'defs' and 'use'-可复用的图元定义

    在下一个示例中,我使用了defs中的元素之前,定义了如何去展现图元. <?xml version="1.0" standalone="no"?> & ...

  2. linux知识点

    通过gui来使用通过api来使用通过cli来使用通过tui来使用 进程不在,但tcp连接还一直存在的解决办法--tcpkill命令 http://www.centoscn.com/CentOS/Int ...

  3. 虚拟化之vmware-网络

    http://blog.sina.com.cn/s/blog_6b89db7a01012jtw.htmlESXI 5.0 虚拟机的网络适配器兼容性列表 就需要在vSphere标准交换机(vSphere ...

  4. C#操作xml SelectNodes,SelectSingleNode总是返回NULL 与 xPath 介绍

    一. SelectNodes,SelectSingleNode总是返回NULL 下面以一个简单的xml为例: <?xml version="1.0"?> <mes ...

  5. C#.Net中的转义字符

    当声明一个字符串变量时有一些字符是不能以平常的方式包含在变量中的.为了解决这个问题,C#提供了两种不同的方法. 第一种方法是使用’转义序列’.例如,我们想得到如下的字符串 “Hello World H ...

  6. C#本地时间和GMT(UTC)时间的转换

    /// <summary> /// 本地时间转成GMT时间 /// </summary> 4 public static string ToGMTString(DateTime ...

  7. nova分析(5)—— nova-conductor

    nova-conductor是nova-compute之上的一个服务,这个服务比较简单,主要封装了DB访问和动态迁移相关的代码.转来一篇文章看看它是如何工作的. 更新记录:1. 2013.4.19   ...

  8. c# win form 显示支付宝二维码图片

    System.Net.WebClient web = new System.Net.WebClient(); byte[] buffer = web.DownloadData(网络图片的地址); we ...

  9. Winform退出程序

    1.this.Close(); 只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出: 2.Application.Exit(); 强制所有消息中止,退 ...

  10. php PDO连接数据库

    [PDO是啥] PDO是PHP 5新加入的一个重大功能,因为在PHP 5以前的php4/php3都是一堆的数据库扩展来跟各个数据库的连接和处理,什么 php_mysql.dll.php_pgsql.d ...