資源描述:
《【無(wú)限互聯(lián)學(xué)員作品】ios開(kāi)發(fā)之mknetworkkit》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫(kù)。
1、無(wú)限互聯(lián)ios開(kāi)發(fā)之mknetworkkitmknetworkkit結(jié)合了ASIHTTPRequest和AFNetworking這兩個(gè)類(lèi)庫(kù)的優(yōu)點(diǎn),也增加了自己的一點(diǎn)新特性,它使用像AFNetworking這么簡(jiǎn)單,而功能像ASIHTTPRequest(已經(jīng)停止維護(hù))那么強(qiáng)大.下載地址:https://github.com/MugunthKumar/MKNetworkKit/將下載包中的MKNetWorkKit文件夾拖到你新建的工程中。添加:SystemConfiguration.framework,CFNetwork.framework,Security.framew
2、ork和ImageIO.framework。目前網(wǎng)上的介紹全都是舊版的MKNetworkKit,新版的MKNetworkKit需要ImageIO.framework,否則會(huì)報(bào)錯(cuò).首先介紹這個(gè)類(lèi)庫(kù)怎么用:get請(qǐng)求:[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];首先床架引擎對(duì)象,在調(diào)用(MKNetworkOperation*)operationWithURLString:(NSString*)urlStringparams:(NSDictionary*)bodyhttpMethod:(NSString*)metho
7、d這個(gè)方法,此方法返回一個(gè)mknetworkOperation對(duì)象,只要將此對(duì)象加入隊(duì)列中即可。此對(duì)象調(diào)用addCompletionHandler:^(MKNetworkOperation*completedOperation)方法會(huì)返回請(qǐng)求過(guò)來(lái)的數(shù)據(jù)。MKNetworkOperation提供了一些如下便捷方法來(lái)方便你格式化你的響應(yīng)數(shù)據(jù)1.responseData2.responseString3.responseJSON(ios5以上)4.responseImage5.responseXML6.error從網(wǎng)絡(luò)請(qǐng)求獲取響應(yīng)很方便,當(dāng)返回格式錯(cuò)誤時(shí),