博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios 使用ASIHTTPRequest来检查版本更新
阅读量:6695 次
发布时间:2019-06-25

本文共 2950 字,大约阅读时间需要 9 分钟。

1 - (void) alertWithTitle: (NSString *)_title_  msg:(NSString *)msg delegate:(id)_delegate cancelButtonTitle:(NSString*)_cancelTitle otherButtonTitles:(NSString*)_otherTitles{ 2     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:_title_ 3                                                     message:msg 4                                                    delegate:_delegate 5                                           cancelButtonTitle:_cancelTitle 6                                           otherButtonTitles:_otherTitles,nil]; 7     [alert show]; 8 } 9 10 #pragma mark - update11 -(void)checkUpdate{12     MBKAppDelegate *mbkApp = (MBKAppDelegate *)[[UIApplication sharedApplication] delegate];13     if (![mbkApp networkIsReach]) {14         return;15     }16     17     NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",kAppId]];18     ASIHTTPRequest *request =[ASIHTTPRequest requestWithURL:url];   19     [request setDelegate:self];20     [request setDidFinishSelector:@selector(requestDone:)];21     [request setDidFailSelector:@selector(requestWentWrong:)];22     [request startSynchronous];23 }24 25 #pragma mark - asihttprequest 26 - (void)requestDone:(ASIHTTPRequest *)request27 {28     NSError *err = nil;29     NSDictionary *dictionary =30     [[CJSONDeserializer deserializer] deserializeAsDictionary:[request responseData] error:&err];31     if (err != nil) {32         [self failure];33         return;34     }35     NSArray *a = [dictionary objectForKey:@"results"];36     if (a.count == 0) {37         [self failure];38         return;39     }40     NSDictionary *d = [a objectAtIndex:0];41     NSString *newVersion = [d objectForKey:@"version"];42     NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];43     NSString *nowVersion = [infoDict objectForKey:@"CFBundleVersion"];44     NSString *msg = @"";45     NSString *cancelTitle = @"";46     NSString *otherTitles = @"";47     if(![nowVersion isEqualToString:newVersion])48     {49         msg = @"版本有更新";50         cancelTitle = @"取消";51         otherTitles = @"更新";52     }else{        53         msg = @"已经是最新版本啦";54         cancelTitle = @"好";55         otherTitles = nil;56     }57     [self alertWithTitle:nil msg:msg delegate:self cancelButtonTitle:cancelTitle otherButtonTitles:otherTitles];58 }59 60 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{61     if(buttonIndex==1){62         NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/qun-xiang-dao/id%@?ls=1&mt=8",kAppId]];63         [[UIApplication sharedApplication]openURL:url];64     }65 }66 67 - (void)requestWentWrong:(ASIHTTPRequest *)request68 {69     [self failure];70 }71 72 - (void)failure{    73     [self alertWithTitle:nil msg:@"检查失败了" delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil];74 }

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

转载地址:http://aopoo.baihongyu.com/

你可能感兴趣的文章
从0移植uboot(六) _实现网络功能
查看>>
Linux命令——du
查看>>
Cube Stacking
查看>>
WPF中DataGrid的ComboBox的简单绑定方式(绝对简单)
查看>>
UIViewContentMode各类型效果
查看>>
转:开启nginx的gzip压缩的相关参数设置
查看>>
转:网站架构-从无到有
查看>>
MUI的一些笔记
查看>>
Jenkins可持续集成Python自动化脚本
查看>>
Linux系统起源及主流发行版
查看>>
跨域问题、跨域cookie问题
查看>>
smarty获取php中的变量
查看>>
linux中wget 、apt-get、yum rpm区别
查看>>
关于Hogan的学习笔记
查看>>
coredump功能介绍
查看>>
Linux内核学习第五周 系统调用
查看>>
第三天,小作业,表达式,while循环
查看>>
HTML5编写规范
查看>>
restful+springmvc+mybatis+ webservice 分布式架构
查看>>
ios语音识别
查看>>