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. Cookielib

    Cookielib模块主要的对象有CookieJar.FileCookieJar.MozillaCookieJar.LWPCookieJar 它们的关系:CookieJar —-派生—->Fil ...

  2. oracle进程

    http://blog.csdn.net/leshami/article/details/5529239 Oracle实例和Oracle数据库(Oracle体系结构) 几类进程:用户进程,服务进程,后 ...

  3. linux服务之smtp

    实现这个协议的软件太多,有sendmail,postfix等.不像snmp,基本上是net-snmp一统天下, yum install nc nc用来取代telnet 这里我们希望让大家知道网络协议中 ...

  4. linux 下查看机器是cpu是几核的

    几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu配置相同) more /proc/cpu ...

  5. Linux 下 apache 日志分析与状态查看[转]

    假设apache日志格式为: 118.78.199.98 – - [09/Jan/2010:00:59:59 +0800] “GET /Public/Css/index.css HTTP/1.1″ 3 ...

  6. 【转】PHP error_reporting() 错误控制函数功能详解

    定义和用法: error_reporting() 设置 PHP 的报错级别并返回当前级别.   函数语法: error_reporting(report_level)   如果参数 level 未指定 ...

  7. 如何将XSD文件以及引入import的文件生成相应的C#类。

    下将微软的 Sample Code Generator 1.4.2.1 如果链接不可以用,请到google上搜索,并安装. 拷贝要生成的XSD相关文件到安装目录,MS-DOS下进入安装目录. 执行命令 ...

  8. You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法

    报错如下:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test2/com.exampl ...

  9. mysql sys table

    本文详细地介绍了MySQL 5.7新引入的sys schema.首先,本文概要地介绍了sys schema的作用和定位:其次,分别介绍了sys schema中的视图.函数和存储过程:接下来,通过两个例 ...

  10. Javascript中函数的四种调用方式

    一.Javascript中函数的几个基本知识点: 1.函数的名字只是一个指向函数的指针,所以即使在不同的执行环境,即不同对象调用这个函数,这个函数指向的仍然是同一个函数. 2.函数中有两个特殊的内部属 ...