访问接口

  • 首先创建一个Header File ,在Header File中写入URL
  • 因为URL开头格式都是以前两段代码为开始,
    所以写入之后直接输入#define+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];
    }
}
}];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 首先创建一个Header File , 在其中写入URL 前两段代码为格式,因为URL开头的格式都是以前两段代码为...
    瞅你咋地阅读 376评论 0 1
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,886评论 18 139
  • 问题: 最近在做一个登录相关的迭代开发时,后台对cookie的支持升级,变的更加“标准”,即:由 原来附在请求头的...
    revolution丶阅读 1,075评论 0 1
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,510评论 0 17
  • 吴兴老鱼阅读 278评论 0 0