priore

Identifies if is running from the device or simulator

Jul 20th, 2016
643
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sys/sysctl.h>
  2.  
  3. + (NSString*)hardwareString
  4. {
  5.     int name[] = {CTL_HW,HW_MACHINE};
  6.     size_t size = 100;
  7.     sysctl(name, 2, NULL, &size, NULL, 0); // getting size of answer
  8.     char *hw_machine = malloc(size);
  9.    
  10.     sysctl(name, 2, hw_machine, &size, NULL, 0);
  11.     NSString *hardware = [NSString stringWithUTF8String:hw_machine];
  12.     free(hw_machine);
  13.     return hardware;
  14. }
  15.  
  16. + (BOOL)isSimulator
  17. {
  18.      BOOL simulator = NO; // default NO for Mac OSX
  19. #if TARGET_OS_SIMULATOR || TARGET_OS_IOS || TARGET_OS_TV
  20.     NSString *hardware = [self hardwareString];
  21.     simulator = [hardware isEqualToString:@"x86_64"];
  22. #endif
  23.     return simulator;
  24. }
RAW Paste Data