当前位置: 首页 > 科技观察

iOS开发需要用到的开源库总结

时间:2023-03-12 20:57:53 科技观察

本人是java&php程序员。遇到iPhone作弊,濒临崩溃被迫学习Object-C。脏,吐问题(弱弱的说:有些问题直到现在才知道具体原理),所以把开发中遇到的问题,需要用到的开源库一一记录下来,给受B的想学Object-C的朋友补充点资料。本文纯属纪实游记文章,欢迎学术观察团和专家回避。在写作过程中,难免出现问题或遗漏。希望大家多多指点和建议!1.iOS&iPhone网络异步加载asi-http-request[1-1ASIHTTP下载地址]https://github.com/pokeb/asi-http-request[1-2注意事项]下载asi-http-request-master解压后,将\Classes文件下的所有文件和\External\Reachabipty文件夹下的所有文件添加到你的项目中。添加对应的pnkBinaryWithpbraries(1)MobileCoreServices.framework(2)SystemConfiguration.framework(3)CFNetwork.framework(4)pbz.dypb由于ARCRestrictionsinBuildPhases输入命令:-fno-objc-arc【1-3小试】引入头文件#import"ASIHTTPRequest.h"更详细的使用方法请参考:http://www.cnblogs.com/zhwl/archive/2012/07/14/2591752.html-(void)viewDidLoad{[superviewDidLoad];//请求后台活动列表NSURL*url=[NSURURRLWithString:@"http://m.weather.com.cn/data/101180701.html"];ASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url];[requestsetDelegate:self];[requeststartAsynchronous];}//异步请求开始-(void)requestStarted:(ASIHTTPRequest*)request{NSLog(@"requeststart:%@",@"start");}//异步请求结束-(void)requestFinished:(ASIHTTPRequest*)request{//UsewhenfetchingtextdataNSString*jsonString=[requestresponseString];NSLog(@"ResponseJSON:%@",jsonString);}//异步请求错误-(void)requestFailed:(ASIHTTPRequest*)request{//NSError*error=[requesterror];NSLog(@"ResponseJSON:%@",@"error");}2.解析JSON数据SBJSON[2-1SBJSON下载地址]https://github.com/stig/json-framework[2-2注释]解压后放将相应的文件导入到项目中,没有发现问题[2-3小测试]在1-3的小测试中,我们请求了天气相关的URL,这个URL会有JSON响应。继续1-3.解析响应JSON-(void)viewDidLoad{[superviewDidLoad];//请求的后台活动列表//NSURL*url=[NSURURLWithString:@"http://192.168.1.4/beer/?cat=2&json=1"];NSURL*url=[NSURURLWithString:@"http://m.weather.com.cn/data/101180701.html"];ASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url];[requestsetDelegate:self];[requeststartAsynchronous];}//异步请求开始-(void)requestStarted:(ASIHTTPRequest*)request{NSLog(@"requeststart:%@",@"start");}//异步请求结束-(void)requestFinished:(ASIHTTPRequest*)request{NSString*jsonString=[requestresponseString];NSLog(@"ResponseJSON:%@",jsonString);SBJsonParser*parser=[[SBJsonParseralloc]init];NSDictionary*rootDic=[parserobjectWithString:jsonString];NSDictionary*weatherInfo=[rootDicobjectForKey:@"weatherinfo"];NSLog(@"ResponseJSONcity:%@",[weatherInfoobjectForKey:@"city"]);}//异步请求错误-(void)requestFailed:(ASIHTTPRequest*)request{//NSError*error=[requesterror];NSLog(@"ResponseJSON:%@",@"error");}3.加载网络数据时,显示onLoading动图MBProgressHUD[3-1MBProgressHUD下载地址]https://github.com/jdg/MBProgressHUD【3-2注意事项】下载后,导入MBProgressHUD.hMBProgressHUD.m暂时还没有发现恶心的问题【3-3小测试】导入头文件MBProgressHUD.h,继续2-3小测试,2-3我们异步读取天气信息,所以需要在请求前显示loading动画,请求结束时,或者网络有问题时需要关闭动画-(void)viewDidLoad{[superviewDidLoad];//请求后台活动列表NSURL*url=[NSURURRLWithString:@"http://m.weather.com.cn/data/101180701.html"];ASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url];[requestsetDelegate:self];[requeststartAsynchronous];}//异步请求开始-(void)requestStarted:(ASIHTTPRequest*)request{NSLog(@"requeststart:%@",@"start");[MBProgressHUDshowHUDAddedTo:self.viewanimated:YES];}//异步请求结束-(void)requestFinished:(ASIHTTPRequest*)request{[MBProgressHUDhideHUDForView:self.viewanimated:YES];NSString*jsonString=[requestresponseString];NSLog(@"ResponseJSON:%@",jsonString);SBJsonParser*parser=[[SBJsonParseralloc]init];NSDictionary*rootDic=[parserobjectWithString:jsonString];NSDictionary*weatherInfo=[rootDicobjectForKey:@"weatherinfo"];NSLog(@"ResponseJSONcity:%@",[weatherInfoobjectForKey:@"city"]);}//异步请求错误-(void)requestFailed:(ASIHTTPRequest*)request{//NSError*error=[requesterror];NSLog(@"ResponseJSON:%@",@"error");[MBProgressHUDhideHUDForView:self.viewanimated:YES];}4.iOS&iPhone异步图片加载EGOImageLoadding[EGOImageLoadding下载地址]https://github.com/enormego/EGOImageLoading[小测试]5.上拉刷新,下拉翻页[5-1EGOTableViewPullRefresh下载地址]https://github.com/enormego/EGOTableViewPullRefresh【5-2注意事项】pnkBinarywithpb需要添加QuartzCore.frameworkFoundation.frameworkCoreGraphics.framework库和[1-2中的注释]6.左侧菜单导航ECSpdingViewController-master:https://github.com/edgecase/ECSpdingViewController