- (void) alertWithTitle: (NSString *)_title_  msg:(NSString *)msg delegate:(id)_delegate cancelButtonTitle:(NSString*)_cancelTitle otherButtonTitles:(NSString*)_otherTitles{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:_title_
message:msg
delegate:_delegate
cancelButtonTitle:_cancelTitle
otherButtonTitles:_otherTitles,nil];
[alert show];
} #pragma mark - update
-(void)checkUpdate{
MBKAppDelegate *mbkApp = (MBKAppDelegate *)[[UIApplication sharedApplication] delegate];
if (![mbkApp networkIsReach]) {
return;
} NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",kAppId]];
ASIHTTPRequest *request =[ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[request startSynchronous];
} #pragma mark - asihttprequest
- (void)requestDone:(ASIHTTPRequest *)request
{
NSError *err = nil;
NSDictionary *dictionary =
[[CJSONDeserializer deserializer] deserializeAsDictionary:[request responseData] error:&err];
if (err != nil) {
[self failure];
return;
}
NSArray *a = [dictionary objectForKey:@"results"];
if (a.count == ) {
[self failure];
return;
}
NSDictionary *d = [a objectAtIndex:];
NSString *newVersion = [d objectForKey:@"version"];
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *nowVersion = [infoDict objectForKey:@"CFBundleVersion"];
NSString *msg = @"";
NSString *cancelTitle = @"";
NSString *otherTitles = @"";
if(![nowVersion isEqualToString:newVersion])
{
msg = @"版本有更新";
cancelTitle = @"取消";
otherTitles = @"更新";
}else{
msg = @"已经是最新版本啦";
cancelTitle = @"好";
otherTitles = nil;
}
[self alertWithTitle:nil msg:msg delegate:self cancelButtonTitle:cancelTitle otherButtonTitles:otherTitles];
} - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex==){
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/qun-xiang-dao/id%@?ls=1&mt=8",kAppId]];
[[UIApplication sharedApplication]openURL:url];
}
} - (void)requestWentWrong:(ASIHTTPRequest *)request
{
[self failure];
} - (void)failure{
[self alertWithTitle:nil msg:@"检查失败了" delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil];
}

转:http://my.oschina.net/brucezcq/blog/148905

ios 使用ASIHTTPRequest来检查版本更新的更多相关文章

  1. iOS - 利用 iTunes 接口检查 App 版本更新

    iOS 想要检查 App 当前版本是否为最新,一般的方案大概都是服务器自己提供一个接口来获取 App 最新版本是多少,然后再做出相应提示是否需要更新,但是接口需要手动维护,应用要审核,还得等审核通过以 ...

  2. iOS子线程操作检测版本更新,有新版本通知用户更新, CheckVersion

    iOS子线程操作检测版本更新,有新版本通知用户更新 CheckVersion 一:如何使用: #import "CheckVersion.h" //输入你的app在appStore ...

  3. ios检查版本更新

            场景 在我们使用应用时,一打开应用,如果此应用有新的版本,常常能在应用中给出提示,是否要更新此应用.所以,我们就来看看,版本更新是如何实现的. 应用 苹果给了我们一个接口,能根据应用i ...

  4. iOS:ASIHttpRequest虽不更新,但仍值得详细了解

    一.使用ASIHTTPRequest可以很方便的进行一下操作:同步/异步方式下载数据,定义下载队列,让队列中的任务按指定的并发数来下载(队列下载必须是异步的),提交表单,文件上传,处理cookie,设 ...

  5. iOS通过ASIHTTPRequest提交JSON数据

    先验知识——什么是ASIHTTPRequest? 使用iOS SDK中的HTTP网络请求API,相当的复杂,调用很繁琐,ASIHTTPRequest就是一个对CFNetwork API进行了封装,并且 ...

  6. iOS用ASIHttpRequest上传

    1.新建一个single view工程,导入ASIHttpRequest库,导入MobileCoreServices.CFNetwork.SystemConfiguration和libz1.2.5.d ...

  7. iOS学习——内存泄漏检查及原因分析

    项目的代码很多,前两天老大突然跟我说项目中某一个ViewController的dealloc()方法没有被调用,存在内存泄漏问题,需要排查原因,解决内存泄漏问题.由于刚加入项目组不久,对出问题的模块的 ...

  8. ios中asihttprequest 下载缓存

    asi中下载缓存第一种方法 #import <UIKit/UIKit.h> #import "ASIHTTPRequest.h" #import "ASIDo ...

  9. ios 的ASIHTTPRequest学习

    发起一个同步请求 同步意为着线程阻塞,在主线程中使用此方法会使应用Hang住而不响应任何用户事件.所以,在应用程序设计时,大多被用在专门的子线程增加用户体验,或用异步请求代替(下面会讲到). - (I ...

随机推荐

  1. hibernate不调用save也保存上了

    List<Instrument> insts = instService.search(search); if (insts.size() == 1) { Instrument inst ...

  2. jQuery.Form插件介绍

    一.前言  jQuery From插件是一个优秀的Ajax表单插件,使用它可以让你非常容易地.无侵入地升级HTML表单以支持Ajax.jQuery From有两个主要方法:ajaxForm和ajaxS ...

  3. 关于Struts2有时候出现的莫名其妙的错误

    有的时候突然出现红色叉叉,但是又不知道哪里错了,解决方法: 1.刷新项目文件夹 2.重启MyEclipse

  4. udhcpc

    /********************************************* * dhcpc * dhcpc是dhcp的客户端,在busybox中实现.今天正好了解一下. * Tony ...

  5. 关于VS2012连接MySql数据库时无法选择数据源

    您的C#开发工具是用VS2012吗?    No! return;    您的数据库用的是MySql吗?     No! return;    您新建ADO.NET数据实体模型的时候选择数据源的时候没 ...

  6. Ajax分页(MVC下)(附源码,前后台)

    网上找的一个分页js,自己改了改.. 前台页面 @{ ViewBag.Title = "Index"; } <h1>分页方法封装</h1> <scri ...

  7. 删除C盘垃圾文件bat

    @ECHO OFF@echo 此批处理由59互联(http://www.59.cn)整理发布@echo @echo 清理几个比较多垃圾文件的地方DEL /F /S /Q "C:\WINDOW ...

  8. PHPCMS列表循环序列号自增标签代码

    {pc:content action="position"posid="1"num="3"thumb="1"} {php ...

  9. GIS-ArcGIS 与 ThreeJs交互联动

    一.从GIS触发Three场景 MapFeatureLayer.on("click", function (evt) { graphicsLayerOfMouse.clear(); ...

  10. 下载SpringJar包

    方法一: 地址:http://repo.spring.io/release/org/springframework/spring/ 此方法简单. 方法二: 安装TortoiseSVN后,在电脑的任意空 ...