Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 如何以编程方式确定我的应用程序是否在 iphone 模拟器中运行?
如果我的程序在模拟器或设备中运行,我如何以常量签入 XCode 4?像这样的东西:
#ifdef RUNING_ON_DEVICE #else #endif
有几个选项
预处理器宏:
#if TARGET_IPHONE_SIMULATOR //is sim #elif TARGET_OS_IPHONE //is real device #else //unknown target #endif
或者,如果您宁愿以某种任意方法进行操作:
if ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone Simulator"]) { //device is simulator }