• AFNetworking 2.0 使用


    AFNetworking 下载地址:https://github.com/AFNetworking/AFNetworking/

    AFNetworking 2.0 当Deployment Target 低于6.0时,AFURLConnectionOperation.h,AFURLSessionManager.h

    @property (nonatomic, strong) dispatch_queue_t completionQueue;

    由于sdk低于6.0时,dispatch_queue_t  ARC没有托管,出现提示错误

     Property with 'retain (or strong)' attribute must be of object type

    修改为

    #if OS_OBJECT_USE_OBJC
    @property (nonatomic, strong) dispatch_queue_t completionQueue;
    #else
    @property (nonatomic, assign) dispatch_queue_t completionQueue;
    #endif

    使用示例:(不使用官方的自带的json和xml解析,返回NSData)

    1.0兼容版

        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        [manager GET:@"http://www.com" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    
        }];

     2.0

        AFHTTPSessionManager *httpSessionManager =[AFHTTPSessionManager manager];
        httpSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
        NSURLSessionDataTask *task = [httpSessionManager GET:@"http://www.com" parameters:nil success:^(NSURLSessionDataTask *task, id responseObject)
        {
    
        } failure:^(NSURLSessionDataTask *task, NSError *error)
        {
            
        }];

    IOS SDK 4.3以上兼容版,需要使用AFNetworking-0.10.x版本

        AFHTTPClient *httpClient = [AFHTTPClient clientWithBaseURL:nil];
        [httpClient getPath:@"http://www.com" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
         {
    
         } failure:^(AFHTTPRequestOperation *operation, NSError *error)
         {
    
         }];
  • 相关阅读:
    线程池3种终止方式比较
    SQL Update多表联合更新的方法
    SQL SERVER 表添加新字段
    JSONObject
    char码值对应列表大全
    JSONOjbect,对各种属性的处理
    Spring MVC ajax提交方式
    docker 初学者 安装 命令
    VMware虚拟机安装CentOS7 设置Nat网络 (超详细)
    关于 i++ 和 ++ i
  • 原文地址:https://www.cnblogs.com/geweb/p/AFNetworking.html
Copyright © 2020-2023  润新知