欢迎来到天天文库
浏览记录
ID:8806687
大小:90.55 KB
页数:10页
时间:2018-04-08
《【无限互联学员作品】ios开发之mknetworkkit》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、无限互联ios开发之mknetworkkitmknetworkkit结合了ASIHTTPRequest和AFNetworking这两个类库的优点,也增加了自己的一点新特性,它使用像AFNetworking这么简单,而功能像ASIHTTPRequest(已经停止维护)那么强大.下载地址:https://github.com/MugunthKumar/MKNetworkKit/将下载包中的MKNetWorkKit文件夹拖到你新建的工程中。添加:SystemConfiguration.framework,CFNetwork.framework,Security.framew
2、ork和ImageIO.framework。目前网上的介绍全都是旧版的MKNetworkKit,新版的MKNetworkKit需要ImageIO.framework,否则会报错.首先介绍这个类库怎么用:get请求:[objc]viewplaincopyprint?1.NSDictionary*dic=[NSDictionarydictionaryWithObject:@"2.00luajUCkXYcfDc0508709c0avmFCE"forKey:@"access_token"];2.MKNetworkEngine*engine=[[MKNetworkEnginea
3、lloc]init];3.MKNetworkOperation*operation=[engineoperationWithURLString:@"https://api.weibo.com/2/statuses/home_timeline.json"params:dichttpMethod:@"GET"];4.[operationaddCompletionHandler:^(MKNetworkOperation*completedOperation){5.NSLog(@"%@",[completedOperationresponseString]);6.}error
4、Handler:^(MKNetworkOperation*completedOperation,NSError*error){7.NSLog(@"%@",[errorlocalizedDescription]);8.}];9.10.[engineenqueueOperation:operation];NSDictionary*dic=[NSDictionarydictionaryWithObject:@"2.00luajUCkXYcfDc0508709c0avmFCE"forKey:@"access_token"]; MKNetworkEngine*engine=[[
5、MKNetworkEnginealloc]init]; MKNetworkOperation*operation=[engineoperationWithURLString:@"https://api.weibo.com/2/statuses/home_timeline.json"params:dichttpMethod:@"GET"]; [operationaddCompletionHandler:^(MKNetworkOperation*completedOperation){ NSLog(@"%@",[completedOperationresponseStri
6、ng]); }errorHandler:^(MKNetworkOperation*completedOperation,NSError*error){ NSLog(@"%@",[errorlocalizedDescription]); }]; [engineenqueueOperation:operation];首先床架引擎对象,在调用(MKNetworkOperation*)operationWithURLString:(NSString*)urlStringparams:(NSDictionary*)bodyhttpMethod:(NSString*)metho
7、d这个方法,此方法返回一个mknetworkOperation对象,只要将此对象加入队列中即可。此对象调用addCompletionHandler:^(MKNetworkOperation*completedOperation)方法会返回请求过来的数据。MKNetworkOperation提供了一些如下便捷方法来方便你格式化你的响应数据1.responseData2.responseString3.responseJSON(ios5以上)4.responseImage5.responseXML6.error从网络请求获取响应很方便,当返回格式错误时,
此文档下载收益归作者所有