iOS AFNetWorking 3.1 的網絡解析

 

AFNetworking 3.0中廢棄:spa

  • 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請求爲例:
 
相關文章
相關標籤/搜索