priore

Identifies if is running from the device or simulator

Jul 20th, 2016
740
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×