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);
...
}
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With