如何检测应用程序是在模拟器或设备上运行
问题描述:
可能重复:
Programmatically detect if app is being run on device or simulator如何检测应用程序是在模拟器或设备上运行
我该如何检测自己的应用程序是否在模拟器上或通过代码运行的设备。
答
记住为您提供了关于设备本身的信息。
[[UIDevice currentDevice] model]
您也可以使用以下方法:
TARGET_IPHONE_SIMULATOR
告诉你,如果你在iPhone模拟器是。
TARGET_OS_IPHONE
告诉您,您正在使用iPhone而不是MacOS。
#if TARGET_IPHONE_SIMULATOR
NSLog(@"Running in Simulator - no app store or giro");
#else
NSLog(@"Running on the Device");
#endif
,当在设备
#if !(TARGET_IPHONE_SIMULATOR)
NSLog(@"Running on device");
#endif
答
只关心你可以使用这个常量
#if TARGET_OS_SIMULATOR
NSLog(@"This is simulator mode....");
#else
NSLog(@"This is device mode....");
#endif
答
相同的已编译的应用程序不能在模拟器和iOS设备都运行,因为CPU指令集完全不同(x86与ARM)。 (...除非你使用lipo构建某种非常奇怪的超级通用二进制文件)
有几种方法可以确定应用程序是否为x86编译。一种是添加运行时代码,这取决于许多预定义的编译器预处理器宏之一。您可以通过在终端命令行中键入以下内容来获得x86编译的预处理器宏列表:
gcc -arch i386 -dM -E - </dev/null |分类
看到这个?? http://*.com/questions/5775420/programmatically-detect-if-app-is-being-run-on-device-or-simulator – Vin 2012-03-15 10:41:49
这么多帖子的副本:http://*.com/questions/ 5122149/iphone-simulator-how-to-detect-when-app-is-running-on-simulator-so-can-setup,http://*.com/questions/5775420/programmatically-detect-if-app- is-being-run-on-device-or-simulator,http://*.com/questions/458304/how-can-i-programmatically-determine- if- my-app-is-running-in-the- iphone-simulato – Sarah 2012-03-15 10:45:58
@富尔维奥抱歉,如果它听起来很刺耳。这个问题在SO上有很多问题。我们不应该在发布之前搜索已经存在的帖子,与我们的问题相关吗? – Vin 2012-03-15 10:50:16