Wednesday, February 20

How to determine if an app is running in the iphone simulator?


If you want to determine if your app is running on the iPhone Simulator or on a device just put the following code somewhere in your app:
#if TARGET_IPHONE_SIMULATOR
    NSLog(@"Hey there! We're running on 'iPhone Simulator'");
#elif TARGET_OS_IPHONE
    NSLog(@"Attention please! We're running on an 'iOS Device");
#endif


This is also an easy way to put in some definitions. For example if the player should run faster on the simulator:
#if TARGET_IPHONE_SIMULATOR
#define MAX_PLAYER_SPEED 145.0
#elif TARGET_OS_IPHONE
#define MAX_PLAYER_SPEED 333.0
#endif