开发者

Target iPhone Simulator Macro Not Working

Using the TARGET_IPHONE_SIMULATOR macro results in the same constant values being defined in am application. For example:

#ifdef TARGET_IPHONE_SIMULATOR
NSString * const Mode = @"Simulator";
#else
NSString * const Mode = @"Device";
#endif

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
   ...
   NSLog(@"Mode: %@", Mode);
   ...
开发者_C百科}

Always results in "Mode: Simulator" being logged. I'm currently running XCode 3.2.4 if that helps. Thanks.


TARGET_OS_SIMULATOR is defined on the device (but defined to false). The fix is:

#include <TargetConditionals.h> // required in Xcode 8+

#if TARGET_OS_SIMULATOR
NSString * const Mode = @"Simulator";
#else
NSString * const Mode = @"Device";
#endif

Not sure when this was changed. I'm fairly sure it was possible to use 'ifdef' in the past.


For me explicitly including TargetConditionals.h helped

#include <TargetConditionals.h>


Try TARGET_OS_SIMULATOR, as TARGET_IPHONE_SIMULATOR is deprecated.


I would try implement macro if its going to be used on different classes through out the app.

in pch file ,

#if TARGET_IPHONE_SIMULATOR
#define isSimulator() YES
#else
#define isSimulator() NO
#endif

and in any class I can check by calling isSimulator().


For some reason TARGET_IPHONE_SIMULATOR doesn't work for me in xcode v6.4 . The snippet below works perfectly :

#if (!arch(i386) && !arch(x86_64))
  camera           = Camera()
#else
  camera           = MockCamera()
#endif


Swift:

#if targetEnvironment(simulator)
    showSimulatorOnlyError()
#endif
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜