AFNetWorking同步方法

title: AFNetWorking同步方法
date: 2015-11-14 11:05:30
categories: IOS

tags: afnetworking

小小程序猿
我的博客:http://daycoding.com

AFNetWoring 同步方法的使用:

NSURL* url = [[NSURL alloc] initWithString:[HOST stringByAppendingString:marker.icon.url]];

NSURLRequest *request = [NSURLRequest requestWithURL:url];
        
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
        
operation.responseSerializer = [AFImageResponseSerializer serializer];
        
/* 最终继承自 NSOperation,看到这个,大家可能就知道了怎么实现同步的了,也就是利用 NSOperation 来做的同步请求 */
      
[operation start];
//同步实现
[operation waitUntilFinished];
        
UIImage* image = (UIImage*)[operation responseObject];
if(image!=nil)
{
  //做处理
}
return nil;

你可能感兴趣的:(AFNetWorking同步方法)