码迷,mamicode.com
首页 > 其他好文 > 详细

封装 block 请求网络数据

时间:2014-10-23 21:09:07      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:封装 block 请求网络数据



NetWorking.h


#import <Foundation/Foundation.h>

typedef void (^FinishBlock)(id responseObject);

@interface NetWorking : NSObject


@property (nonatomic ,strong) FinishBlock finishBlock;


+(void)GetDataWithURL:(NSString *)url finshedBlock:(FinishBlock)block;


@end




NetWorking.m


#import "NetWorking.h"
#import "AFNetworking.h"
@implementation NetWorking



+(void)GetDataWithURL:(NSString *)url finshedBlock:(FinishBlock)block
{
    NetWorking * request = [[NetWorking alloc]init];
    request.finishBlock = block;
    
    AFHTTPRequestOperationManager *manager =
    [AFHTTPRequestOperationManager manager];
    [manager GET:url
      parameters:nil
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             if (request.finishBlock) {
                 request.finishBlock(responseObject);
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             NSLog(@"Error: %@", error);
         }];
}
@end

封装 block 请求网络数据

标签:封装 block 请求网络数据

原文地址:http://qccccc.blog.51cto.com/6004423/1567207

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!