首页 > Web开发 > 详细

AFHTTPClient的异步回调模式

时间:2015-07-08 22:39:04      阅读:182      评论:0      收藏:0      [点我收藏+]

以前第一个版本,ios的http都用的同步模式,在很多地方会导致线程阻塞,自己开发了一个简易的AFHTTPClient的异步回调模式。

 

回调的protocol:

@protocol MyAFNetworkingResponse <NSObject>

@required

-(void) MyHttpResponse:(NSString*)ret Type:(NSString*)strType returnData:(NSObject*)retData;

@end

 

AFHTTPClient的异步通信的实现类:

@interface MyAFNetworkingClient : AFHTTPClient

@property NSURL* mServerUrl;//http服务地址

@property id<MyAFNetworkingResponse> delegate;//这个最重要,回调的代理

 

//类初始化函数

- (id)init;

- (id)initWithBaseURL:(NSURL *)url;

 

/*然后是一堆实现的函数*/

.....

@end

 

然后viewcontroller中:

@interface MainViewController ()< MyAFNetworkingResponse>

@end

@implementation MainViewController

- (void)viewDidLoad {

    [super viewDidLoad];    

    //初始化

    self.mAFNetworkingHttpClient = [[MyAFNetworkingClient allocinit];

    self.mAFNetworkingHttpClient.delegate = self;

}

 

-(void) MyHttpResponse:(NSString*)ret Type:(NSString*)strType returnData:(NSObject*)retInfo{

    __weak MainViewController* wself = self;

    if ([strType isEqualToString:@"xxxx"]) {

         //某个具体http类型的,实现处理

    }else if([strType isEqualToString:@"xxxx"]){

          //某个具体http类型的,实现处理

    }

}

@end

版权声明:本文为博主原创文章,未经博主允许不得转载。

AFHTTPClient的异步回调模式

原文:http://blog.csdn.net/u012917616/article/details/46808083

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!