[英]Detect in Xcode iPhone project whether I'm building for simulator or device?
Is there any way I can conditionally compile in my app based upon whether I'm building for the simulator or the device? 有没有什么方法可以根据我是在为模拟器还是设备构建而在我的应用程序中有条件地编译? (My app hooks to an external server: if I'm running on the device, I want to connect to localhost; if I'm running on the device, I want to go to my production server.)
(我的应用程序挂钩到外部服务器:如果我在设备上运行,我想连接到localhost;如果我在设备上运行,我想去我的生产服务器。)
I'm looking for some #ifdef variable I can detect, or even something at runtime...doesn't matter. 我正在寻找一些我可以检测到的#ifdef变量,甚至是运行时的东西...无所谓。
Thanks. 谢谢。
I created a macro in which you can specify which actions you want to perform inside parentheses and these actions will only be performed if the device is being simulated. 我创建了一个宏,您可以在其中指定要在括号内执行的操作,并且只有在模拟设备时才会执行这些操作。
#define SIM(x) if ([[[UIDevice currentDevice].model lowercaseString] rangeOfString:@"simulator"].location != NSNotFound){x;}
This is used like this: 这是这样使用的:
SIM(NSLog(@"This will only be logged if the device is simulated"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.