訪問接口

  • 首先創建一個Header File , 在其中寫入URL

前兩段代碼為格式,因為URL開頭的格式都是以前兩段代碼為開始,所以寫入之后以后直接輸入#define+URL就可以了。

#define IP @"http://dalianmohekeji.eicp.net:8102/repastmanage"
#define URL(api)   [ NSString stringWithFormat:@"%@%@",IP,api]
 #define ******* (輸入URL)@"/clientAPI/searchRestaurantList.json"
-(void)getData{
    //    //cityId:城市ID
    //    //lat:緯度
    //    //lng:經度
    //showType
    //sendPrice
    // defaultOeder
   //實例化一個字典 
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    // 在字典中寫入key
    NSDictionary *userInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserInfo"];
    //向dic中傳值
    [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];// 提示用戶正在請求
    [[SetRequest sharedInstance]postRequestWithURL:URL(*********輸入URL)
    postParems:dic content:^(NetWorkModel *model){        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        if(model.error){            
            NSLog(@"獲取列表失敗");
        }else{            
            if ([model.responseDic[@"error_code"] intValue] == 0) {                      
               _dataSource = model.responseDic[@"restaurantList"];                
                [_tableView reloadData];                
            }
        }
    }];
}


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 首先創建一個Header File ,在Header File中寫入URL 因為URL開頭格式都是以前兩段代碼為開...
    你瞅誰閱讀 400評論 0 4
  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,869評論 18 139
  • 問題: 最近在做一個登錄相關的迭代開發時,后臺對cookie的支持升級,變的更加“標準”,即:由 原來附在請求頭的...
    revolution丶閱讀 1,075評論 0 1
  • iOS網絡架構討論梳理整理中。。。 其實如果沒有APIManager這一層是沒法使用delegate的,畢竟多個單...
    yhtang閱讀 5,251評論 1 23
  • 終于在今天結束了這個話題,人類進行的精神交流與肉體欲望都是我所不能理解的,或許本就不是一個擅長交往的對象,希望改進...
    Saminyarmena閱讀 337評論 0 0