ios 使用ASIHTTPRequest来检查版本更新
2013-08-27 15:50
471 查看
- (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 == 0) { [self failure]; return; } NSDictionary *d = [a objectAtIndex:0]; 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==1){ 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 类库简介和使用说明
- ASIHTTPRequest类库简介和使用说明以及Google App Engine for ios(转)
- iOS开发ASIHTTPRequest中Cookie的使用
- iOS开发asi使用(二)ASIHttpRequest发送数据
- IOS网络篇9之ASIHttpRequest的使用
- iOS学习--ASIHTTPRequest类库简介和使用说明
- iOS网络开发编程之NSURLConnection详解 iOS网络层常用的库如ASIHTTPRequest,AFNetworking,MKNetworkKit等知名的第三方库。随着ASI不再更新,楼主
- iOS学习之-使用ASIHttpRequest调用WebService
- 【读书笔记】iOS-ASIHTTPRequest框架的使用。
- ios学习--ASIHTTPRequest类库简介和使用说明
- iOS--ASIHTTPRequest类库的添加和使用
- iOS开发ASIHTTPRequest使用download cache
- IOS使用Swift+ASIHttpRequest出现 -1005情况
- IOS ASIHTTPRequest类库简介和使用说明
- IOS ASIHttpRequest使用详解
- iOS 使用ASIHTTPRequest实现图片下载,断点续传,cell自定义
- 【读书笔记】iOS-ASIHTTPRequest框架的使用。
- iOS 使用ASIHttpRequest和GData解析xml网络文件
- ios 使用webservice restful api使用ASIHttpRequest即可,restKit较大,可放后
- iOS学习--uexiASIHTTPRequest使用指南---<<翻译稿>>