The Afnetworking Auxiliary class

Source: Internet
Author: User

Use:

1. Pour the afnetworking frame

2. Pour the HlAFNetworkingHelperClasses.h file where requested

3.

/**

1. Request Address: String type

2. Request method: Hlpost Hlget

3. Request Parameters: Dictionary type

*/

[hlafnetworkinghelperclasses hlcomprehensivehttp: Request address Httpclass: Request method Data: Request entry Value: ^ (nsdictionary *dic) {

NSLog (@ "return result:%@", DIC);

} Error: ^ (ID error) {

NSLog (@ "Failure reason:%@", error);

}];

1 //2 //HlAFNetworkingHelperClasses.h3 //Hlblockweb4 //5 //Created by Huang Lei on 16/3/22.6 //copyright©2016 year Huang Lei. All rights reserved.7 //8 9#import <Foundation/Foundation.h>Ten  One#import"HttpConfig.h" A  - @interface Hlafnetworkinghelperclasses:nsobject -  the /* - Rich enumeration type (Network request type) -  */ - typedef ns_options (Nsinteger, httpclass) { +Hlget =0,//GET Request -Hlpost =1//POST Request + }; A  at  - /** - afnetworking Auxiliary Implementation class - -------------------------Request type post---------------------- - parameter URL network request address - Parameters dic Network Request Parameters in Returnmethod return a result dictionary - Error return Failure reason to  */ ++(void) Hlpost: (NSString *) URL -Data: (Nsdictionary *) DiC theValue: (void(^) (Nsdictionary *dic)) Returnmethod *Error: (void(^) (ID error)) hlerror; $ Panax Notoginseng /** - ------------------Request type get----------------------- the parameter URL network request address + Parameters dic Network Request Parameters A Returnmethod return a result dictionary the Error return Failure reason +  */ -+(void) Hlget: (NSString *) URL $Data: (Nsdictionary *) DiC $Value: (void(^) (Nsdictionary *dic)) Returnmethod -Error: (void(^) (ID error)) hlerror; -  the /** - ------------------GET Post Collection Method---------------------Wuyi parameter URL network request address the parameter Httpclass request type - Parameters dic Network Request Parameters Wu Returnmethod return a result dictionary - Error return Failure reason About  */ $+(void) Hlcomprehensivehttp: (NSString *) URL - Httpclass: (Httpclass) Httpclass -Data: (Nsdictionary *) DiC -Value: (void(^) (Nsdictionary *dic)) Returnmethod AError: (void(^) (ID error)) hlerror; +  the  -@end
hlafnetworkinghelperclasses.m//hlblockweb////Created by Huang Lei on 16/3/22.//copyright©2016 year Huang Lei. All rights reserved.//#import "HlAFNetworkingHelperClasses.h" #import "AFNetworking.h" #import "WringViewController.h        "@implementation Hlafnetworkinghelperclasses//hlpost network request + (void) Hlpost: (NSString *) URL Data: (nsdictionary *) dic Value: (void (^) (nsdictionary *dic)) Returnmethod Error: (void (^) (id Error)) hlerror{//Send network request with afnetworking I F (Returnmethod && hlerror) {Afhttprequestoperationmanager *manager = [Afhttprequestoperationmanager manag        ER]; [Manager Post:url Parameters:dic success:^ (afhttprequestoperation *operation, id responseobject)        {Returnmethod (responseobject);        } failure:^ (Afhttprequestoperation *operation, Nserror *error) {hlerror (error);    }]; }}//hlget Network request + (void) Hlget: (NSString *) URL Data: (nsdictionary *) dic Value: (void (^) (nsdictionary *)) Returnmeth OD Error: (void (^)(ID)) hlerror{//Send network request with Afnetworking if (Returnmethod && hlerror) {Afhttprequestoperationmanager *manage        R = [Afhttprequestoperationmanager manager]; [Manager Get:url Parameters:dic success:^ (afhttprequestoperation *operation, id responseobject)        {Returnmethod (responseobject);        } failure:^ (Afhttprequestoperation *operation, Nserror *error) {hlerror (error);    }];                      }}//Integrated Network request method + (void) Hlcomprehensivehttp: (NSString *) URL Httpclass: (httpclass) Httpclass Data: (nsdictionary *) dic Value: (void (^) (nsdictionary *dic)) Returnmethod Error: (vo ID (^) (ID error)) hlerror{if ([[[[Httpconfig Instance] isnetwork] isequaltostring:@ "NO"]) {[Wringviewcontroller H    lalitewring:@ "No network Connection" height:44];                }else{if (Httpclass = = hlpost) {[Self Hlpost:url data:dic value:^ (nsdictionary *dic) {            Returnmethod (DIC); } error:^ (ID ERror) {hlerror (error);        }]; }else if (Httpclass = = Hlget) {[Self Hlget:url data:dic value:^ (nsdictionary *dic) {Returnmetho            D (DIC);            } error:^ (id error) {hlerror (error);        }]; }}} @end

Afnetworking Helper Class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.