XCode - 如果我的程序在模拟器o设备中运行,请检查常量

BQu*_*dra 0 objective-c xcode4

可能重复:
如何以编程方式确定我的应用程序是否在iphone模拟器中运行?

如果我的程序在模拟器o设备上运行,我如何用常量检查XCode 4?像这样的东西:

#ifdef RUNING_ON_DEVICE
#else
#endif
Run Code Online (Sandbox Code Playgroud)

Mic*_*lum 6

有几种选择

预处理器宏:

#if TARGET_IPHONE_SIMULATOR
//is sim
#elif TARGET_OS_IPHONE
//is real device
#else
//unknown target
#endif
Run Code Online (Sandbox Code Playgroud)

或者,如果您宁愿以某种方式执行此操作:

if ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone Simulator"]) {
    //device is simulator
}
Run Code Online (Sandbox Code Playgroud)