A simple package of iOS crazy ASIHTTPRequest
WLHTTPClient.h
Wlwllisten
//
Created by long on 14-12-15.
Copyright (c) 2014 Wlong. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ASIFormDataRequest.h"
@protocol wlhttpclientdelegate<nsobject>
@optional
@end
@interface Wlhttpclient:nsobject
@property (nonatomic,assign) id<wlhttpclientdelegate>delegate;
+ (wlhttpclient *) sharedclient;
-(void) Postinfowithdelegate: (id<wlhttpclientdelegate>) delegate
Withmethod: (NSString *) method
Withparams: (nsdictionary *) params
Withsuccuessmethod: (SEL) Successmethod
Withfailedmethod: (SEL) Failmethod;
@end
//
Wlhttpclient.m
Wlvkolisten
//
Created by long on 14-12-15.
Copyright (c) 2014 Wlong. All rights reserved.
//
#import "WLHTTPClient.h"
#define SUPPRESSPERFORMSELECTORLEAKWARNING (Stuff) \
do {\
_pragma ("clang diagnostic push") \
_pragma ("clang diagnostic ignored \"-warc-performselector-leaks\ "") \
Stuff; \
_pragma ("clang diagnostic pop") \
} while (0)
@implementation Wlhttpclient
+ (Wlhttpclient *) sharedclient
{
static wlhttpclient *_sharedclient = nil;
Static dispatch_once_t Oncetoken;
Dispatch_once (&oncetoken, ^{
_sharedclient = [[Wlhttpclient alloc]init];
});
return _sharedclient;
}
-(void) Postinfowithdelegate: (id<wlhttpclientdelegate>) delegate
Withmethod: (NSString *) method
Withparams: (nsdictionary *) params
Withsuccuessmethod: (SEL) Successmethod
Withfailedmethod: (SEL) Failmethod
{
NSString *urlstr = [NSString stringwithformat:@ "%@%@", Basehttpurl,method];
__weak asiformdatarequest *request = [asiformdatarequest requestwithurl:[nsurl urlwithstring:urlstr]];
[Request setrequestmethod:@ "POST"];
for (int i = 0; i < [params allkeys].count; i++) {
[Request Addpostvalue:params[[params Allkeys][i]] forkey:[params allkeys][i];
}
[Request setcompletionblock:^{
NSData *jsondata = Request.responsedata;
ID result = [nsjsonserialization jsonobjectwithdata:jsondata options:nsjsonreadingmutablecontainers Error:nil];
Suppressperformselectorleakwarning (
[Delegate Performselector:successmethod Withobject:result];
);
}];
[Request setfailedblock:^{
Suppressperformselectorleakwarning (
[Delegate Performselector:failmethod withobject:@ "Network connection failed, please check your network connection or retry! "];
);
}];
[Request startasynchronous];
}
@end
More iOS Madness: Http://blog.csdn.net/wanglongblog
A simple package of iOS crazy ASIHTTPRequest