iOS AFNetWorking 3.1 的网络解析

时间:2022-10-21 09:23:13

AFNetworking 3.0中废弃:

  • AFURLConnectionOperation
  • AFHTTPRequestOperation
  • AFHTTPRequestOperationManager
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
 
    AFURLSessionManager *manage = [[AFURLSessionManager alloc]initWithSessionConfiguration:configuration];
 
    NSMutableURLRequest *reguest = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"GET" 或者@"POST"  URLString:[NSString stringWithFormat:@"网址"]  parameters:nil error:nil];
 
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
 
 NSURLSessionDataTask *task = [manage dataTaskWithRequest:reguest completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (error) {
            NSLog(@"error:%@",error);
        }else{
          model的赋值  
        }
    }];
    [task resume];
}
 
贴上代码以GET请求为例:
 
iOS AFNetWorking 3.1 的网络解析