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. ID3算法 决策树的生成(2)

    # coding:utf-8 import matplotlib.pyplot as plt import numpy as np import pylab def createDataSet(): ...

  2. addClass的用法和is函数的用法

    <html> <head> <meta charset="utf-8"> <script type="text/javascri ...

  3. QQ登入(5)获取空间相册,新建相册,上传图片到空间相册

    ///////////////////////////////////////////////////////////////////// 获取相册列表:必须先授权登入 1.1.  String mA ...

  4. vb6异步ADO操作

    Private withevents M_Conn as adodb.connection Private CmdFinished as boolean sub somesub AdoCmd.Exec ...

  5. hibernate反向工程 (eclipse和myeclipse)(转)

    hibernate反向工程 (eclipse和myeclipse) 如何提取数据库的模式信息,想通过hibernate的反向工具尝试下. 一.myeclipse下hibernate反向工程: 1.选择 ...

  6. #linux包之tcpdump之tcpdump命令

    概述 man tcpdump 已阅 yum install tcpdump Downloading Packages:(1/2): libpcap-1.4.0-1.20130826git2dbcaa1 ...

  7. Android App监听软键盘按键的三种方式

    前言:   我们在android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“GO”按键加载url页面:在点击搜索框的时候,点击右下角的sea ...

  8. spring-boot支持双数据源mysql+mongo

    这里,首先想说的是,现在的web应用,处理的数据对象,有结构化的,也有非结构化的.同时存在.但是在spring-boot操作数据库的时候,若是在properties文件中配置数据源的信息,通过默认配置 ...

  9. (转)mongodb分片

    本文转载自:http://www.cnblogs.com/huangxincheng/archive/2012/03/07/2383284.html 在mongodb里面存在另一种集群,就是分片技术, ...

  10. bzoj3743 Kamp

    Description 一颗树n个点,n-1条边,经过每条边都要花费一定的时间,任意两个点都是联通的. 有K个人(分布在K个不同的点)要集中到一个点举行聚会. 聚会结束后需要一辆车从举行聚会的这点出发 ...