IOS-返回接口相关的
2015-12-11 本文已影响240人
Roger_单
- 实例化个可变字典
- 通过URL是拼接的,是一个宏和另个宏拼接而成的。
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"];
- 提示用户请求
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
-
打印
dic
-
获取接口请求
[[SetRequest sharedInstance]postRequestWithURL:URL(searchSupermarketList)
postParems:dic content:^(NetWorkModel *model){
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
if(model.error){
[[UIToast makeText:@"发送失败"] show];
}else{
NSLog(@"发送搜索请求失败");
if ([model.responseDic[@"error_code"] intValue] == 0) {
// [[UIToast makeText:@"搜索成功,请查收!"] show];
_dataSource = [[NSArray alloc]init];
if (![model.responseDic[@"restaurantList"] isKindOfClass:[NSNull class]]) {
_dataSource = model.responseDic[@"restaurantList"];
}
[_tableView reloadData];
}else{
[[UIToast makeText:@"请求失败"] show];
}
}
}];
- 打印
responseDic
- 并调用
#import "UIToast.h"
让其成功失败给与用户显示。