访问接口

作者: 你瞅誰 | 来源:发表于2015-12-11 15:59 被阅读161次
  • 首先创建一个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开头的格式都是以前两段代码为...

  • 访问接口

    有参数 有URL 参数是//cityId:城市ID//lat:纬度//lng:经度//showType//send...

  • 访问接口

    首先创建一个Header File ,在Header File中写入URL 因为URL开头格式都是以前两段代码为开...

  • laravel 事务与锁

    结论: 首先访问了test接口后再访问testName接口,发现testName接口没有一直处在request请求...

  • 访问权限

    2.1 public:接口访问权限 具有最大的访问权限,可以访问任何一个在classpath下的类、接口、异常...

  • redis+jwt+springBoot/springMvc逆向

    前提条件:访问接口先通过token拦截器(统一配置) 1.首次访问:访问登录接口,登录接口生成一个无期的token...

  • 用python为mysql实现restful接口

    点击访问 API接口

  • Action

    访问Servlet接口 ActionContext 实现接口ServletContextAware... Serv...

  • Hadoop | 访问接口

    1. 访问接口综述 2. 浏览器接口 3. 命令行接口

  • 移动架构--13.简单仿网络访问框架

    1.提供网络请求的包装类 2.网络访问结果回调接口 3.网络访问具体实现接口 4.供应用层回调的网络访问回调接口 ...

网友评论

    本文标题:访问接口

    本文链接:https://www.haomeiwen.com/subject/mduyhttx.html