Information and Links
How to find out if your iPhone app is running in the iPhone Simulator
Sometimes it is useful to run different code when your iPhone application is being tested in the iPhone Simulator rather than on a real iPhone or iPod Touch device. For example, if you are testing CoreLocation functionality in the Simulator, all of CoreLocation’s returned locations will be for somewhere in Cupertino – not much use for testing with non-US data.
Checking for the Simulator is pretty simple, as shown in the code below.
#if TARGET_IPHONE_SIMULATOR
NSString *hello = @”Hello, iPhone simulator!”;
#elif TARGET_OS_IPHONE
NSString *hello = @”Hello, device!”;
#else
NSString *hello = @”Hello, unknown target!”;
#endif
(This is a major edit of my original article, with many thanks to H from OfCodeAndMen, who pointed out that my original approach was rubbish, and suggested the approach above instead.)



Don’t use __i386__. For many reasons. In this case, one of the obvious is either if the iPhone goes i386 or the Mac changes its CPU. Or something along those lines.
There is a _documented_ way to do what you want to. The following code works:
#if TARGET_IPHONE_SIMULATOR
NSString *hello = @”Hello, iPhone simulator!”;
#elif TARGET_OS_IPHONE
NSString *hello = @”Hello, device!”;
#else
NSString *hello = @”Hello, unknown target!”;
#endif