iOS DeveloperiOS开发记录

访问接口

2015-12-11  本文已影响161人  你瞅誰
  • 首先创建一个Header File ,在Header File中写入URL
-(void) getsearchSupermarketList{
//cityId:城市ID,或分区ID
//lat:纬度
//lng:经度
//tasteCategory: 1//根据口味接口裂变返回值
//restaurantName:餐厅名称
//type:所搜类型(1:点餐、2:预约、3:外卖)
//showType:查询方式(-1:全部查询;  >0 (1,2,3,4...):分页查询按传参算页数)
    // 入力参数
    //实例化一个可变字典,填写参数
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    NSDictionary *userInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserInfo"];
      [dic setValue:userInfo[@"supermaketName"] forKey:@"supermaketName"];//空数组
      [dic setValue:userInfo[@"tasteCategory"] forKey:@"tasteCategory"];//空数组
      [dic setValue:@"0411" forKey:@"ctiyId"];
      [dic setValue:[NSNumber numberWithDouble:121.517977] forKey:@"lng"];
      [dic setValue:[NSNumber numberWithDouble:38.8496481] forKey:@"lat"];
      [dic setValue:userInfo[@"type"] forKey:@"type"];//空数组
      [dic setValue:@"1" forKey:@"showType"];

    //打印 dic
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];// 提示用户正在请求
    
    //获取接口请求 (异步走到定位)
    [[SetRequest sharedInstance]postRequestWithURL:URL(*****)
       postParems:dic content:^(NetWorkModel *model){
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

//error 传dic(参数)的值,请求成功nil. 请求失败 [[UIToast makeText:@"发送失败"] show];
 if(model.error){
    NSLog(@"获取列表失败");
    [[UIToast makeText:@"发送失败"] show];
    }else{
    NSLog(@"发送搜索请求成功");
        
    //打印 model.responDic
    if ([model.responseDic[@"error_code"] intValue] == 0) {
    _dataSource = [[NSArray alloc]init];
        
    if (![model.responseDic[@"restaurantList"] isKindOfClass:[NSNull class]]) {
    _dataSource = model.responseDic[@"restaurantList"];
    }
        
    // reload tableView(重新加载数据,更新)
        [_tableView reloadData];
    }else{
        [[UIToast makeText:@"请求失败"] show];
    }
}
}];
}
上一篇 下一篇

猜你喜欢

热点阅读