About mknetworking Own maintenance
Personal comparisons tend to be mknetworking, because in small projects this network request framework can be said to be lightweight. But there is a part of the function missing or functional surplus, and need to optimize the place. So decided to maintain a MK repo for his own use.
In github:mknetworking-dlprotecting here you can see the source code and demo project.
0.INIT
1.GET
-Get/download-//Use Operationwithpath: Create operation, will automatically stitching Engin host and Apipath, etc.mknetworkoperation * operation = [Engin Operationwithpath:@ "Student.json" params:Nil HttpMethod:@ "GET" SSL:NO];Use operationwithurlstring: Create operation, do not stitch Engin host and ApipathMknetworkoperation * Operation_url = [Engin operationwithurlstring:@ "Http://api.devdylan.com/MKNetFrame/Student.json" params:Nil HttpMethod:@ "GET"];NSLog (@ "%@", Operation. URL);NSLog (@ "%@", Operation_url. URL); [Operation Addcompletionhandler:^ (mknetworkoperation *completedoperation) { //Here the request is processed at the right time NSLog (@ "%@", Completedoperation. Responsejson); if ([completedoperation Iscachedresponse]) { //What you get now is the data in the cache} else { //You are now getting data from the server}} errorhandler:^ (mknetworkoperation *completedoperation, nserror *error) { //This returns server-level errors or JSON parsing errors. NSLog (@ "%@", completedoperation. Error);}]; //execute current network request [Engin Enqueueoperation:operation];
2.POST
-Post/upload-//Mknetworkoperation * Operation_post = [Engin Operationwithpath:@ "Student.json" Params:nil HttpMethod: @ "POST" Ssl:no]; [Operation_post addcompletionhandler:^ (mknetworkoperation *completedOperation) {//here to handle the request right when nslog (@ "%@", Completedoperation.responsejson); } errorhandler:^ (mknetworkoperation *completedoperation, Nserror *error) {//This returns server-level errors or JSON parsing errors. nslog (@ "%@", completedoperation .error); }]; [Engin enqueueoperation:operation_post forcereload:yes]; //set unread cache
3.UPLOAD
// 添加路径下文件 [operation_post addFile:@"FILE PATH" forKey:@"image.png"]; // 添加Data [operation_post addData:[NSData data] forKey:@"image2.png"]; [operation_post onUploadProgressChanged:^(double progress) { // 上传进度 }];
4.DOWNLOAD
// 下载文件时, 添加下载流 [operation addDownloadStream:[NSOutputStream outputStreamToFileAtPath:@"downloadPath/image.png" append:YES]]; [operation onDownloadProgressChanged:^(double progress) { // 下载进度 }];
5.FORCELOAD
[engin enqueueOperation:operation_post forceReload:YES]; // 设置不读缓存
6.FREEZABLE
// 设置当前operation冻结 [operation_post setFreezable:YES]; // 解除冻结 [operation_post setFreezable:NO];
7.OTHERS
[Operation_post onnotmodified:^{//call at Server 304}]; Cancel Request[Operation_post Canceloperation]; Request only in WiFi case, default is no Engin.wifionlymode = YES[engin Cancelalloperation][ Engin removeoperation:operation_post][engin emptycache]; [engin setreachabilitychangedhandler:^ (networkstatus statu) {//Handle the change of network status}] [operation_post Setoperationstatechangedhandler:^ (mknetworkoperationstate state) {//When operation status changes, back to here}]
About mknetworking Own maintenance