使用TARGET_IPHONE_SIMULATOR
宏会导致在am应用程序中定义相同的常量值。例如:
#ifdef TARGET_IPHONE_SIMULATOR
NSString * const Mode = @"Simulator";
#else
NSString * const Mode = @"Device";
#endif
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
...
NSLog(@"Mode: %@", Mode);
...
}
总是导致“模式:模拟器”被记录。我目前运行的是XCode 3.2.4,如果有帮助的话。谢谢。
发布于 2010-08-07 05:27:52
在设备上定义了TARGET_OS_SIMULATOR
(但定义为false)。修复方法是:
#include <TargetConditionals.h> // required in Xcode 8+
#if TARGET_OS_SIMULATOR
NSString * const Mode = @"Simulator";
#else
NSString * const Mode = @"Device";
#endif
不确定这是何时更改的。我非常确定在过去使用'ifdef‘是可能的。
发布于 2015-09-07 22:20:12
对我来说,显式地包括TargetConditionals.h
帮助
#include <TargetConditionals.h>
发布于 2015-10-27 22:11:10
尝试使用TARGET_OS_SIMULATOR,因为TARGET_IPHONE_SIMULATOR已被弃用。
https://stackoverflow.com/questions/3427888
复制相似问题