2017-03-06 52 views
0

下面是我用來選擇IP的宏。彈出一個警報視圖,用戶嘗試登錄,基於相應的IP被設置爲從服務器獲取數據。宏保留靜態值

static NSString *[email protected]"http://%@/api/Home/editProfile/ios/1"; 


#define getServerURl(url,selectdServer)[[NSString stringWithFormat:@"%@",url] stringByReplacingOccurrencesOfString:@"%@" 
withString:([selectdServer isEqualToString:@"live"] [email protected]"live_ip/folder_name":@"demo_ip/folder_name")] 
  1. 我選擇了 'demo_ip' 選項登錄。
  2. 退出。
  3. 現在選擇「實時」選項。 這裏的問題是demo_ip在某些地方被調用。請幫助。

感謝

回答

1

你可以嘗試這樣的:

#define USE_TEST_URL 1 // use 1 for test and 0 for live 

#if USE_TEST_URL // define test urls here 

#define API_URL @"http://...<TEST URL>" 

#else // define live urls here 

#define API_URL @"http://... <LIVE URL>" 

#endif 

NSString *url =[[NSString stringWithFormat:@"%@",API_URL] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
1

有沒有與宏觀的問題,有可能一直是個問題與您傳遞參數,當您調用getServerURl(...)

當您需要直播時,請確保您將'live'傳遞給getServerURl(...)的第二個參數!因爲您有條件地比較「實時」小寫值。

欲瞭解更多信息:在您的源文件甚至編譯之前,宏由預處理器的值替換。所以你不可能在運行時改變宏的值。

enter image description here