下面是我用来选择IP的宏。弹出一个警报视图,用户尝试登录,其基础是将相应的IP设置为从服务器获取数据。
static NSString *updateProfileDetails_URL=@"http://%@/api/Home/editProfile/ios/1";
#define getServerURl(url,selectdServer)[[NSString stringWithFormat:@"%@",url] stringByReplacingOccurrencesOfString:@"%@"
withString:([selectdServer isEqualToString:@"live"] ?@"live_ip/folder_name":@"demo_ip/folder_name" )]
谢谢
发布于 2017-03-06 12:39:36
你可以这样做:
#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];
发布于 2017-03-06 12:47:12
宏没有问题,调用getServerURl(.)时,传递参数可能有问题。
当您需要live时,请确保在getServerURl(.)的第二个参数中传递'live‘!因为您在有条件地比较“实时”小写值。
有关更多信息:宏在源文件编译之前就被预处理程序替换为它们的值。因此,您不可能在运行时更改宏的值。
https://stackoverflow.com/questions/42625426
复制相似问题