code_junkie

How can I programmatically determine if my app is running in the iphone simulator

Nov 13th, 2011
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include "TargetConditionals.h"
  2.  
  3. #ifdef __APPLE__
  4. #include "TargetConditionals.h"
  5. #endif
  6.  
  7. #if !(TARGET_IPHONE_SIMULATOR)
  8.  
  9. #ifdef __i386__
  10. NSLog(@"Running in the simulator");
  11. #else
  12. NSLog(@"Running on a device");
  13. #endif
  14.  
  15. #if TARGET_IPHONE_SIMULATOR
  16. NSString *hello = @”Hello, iPhone simulator!”;
  17. #elif TARGET_OS_IPHONE
  18. NSString *hello = @”Hello, device!”;
  19. #else
  20. NSString *hello = @”Hello, unknown target!”;
  21. #endif
  22.  
  23. NSString *model = [[UIDevice currentDevice] model];
  24. if ([model isEqualToString:@"iPhone Simulator"]) {
  25. //device is simulator
  26. }
  27.  
  28. #if TARGET_IPHONE_SIMULATOR
  29.  
  30. #ifdef TARGET_IPHONE_SIMULATOR
  31.  
  32. #if defined __arm__ || defined __thumb__
  33. #undef TARGET_IPHONE_SIMULATOR
  34. #define TARGET_OS_IPHONE
  35. #else
  36. #define TARGET_IPHONE_SIMULATOR 1
  37. #undef TARGET_OS_IPHONE
  38. #endif
Add Comment
Please, Sign In to add comment