Skip to content

Instantly share code, notes, and snippets.

@priore
Created July 20, 2016 14:13
Show Gist options
  • Select an option

  • Save priore/73d59a4f565e95189b03c0d2ca923f36 to your computer and use it in GitHub Desktop.

Select an option

Save priore/73d59a4f565e95189b03c0d2ca923f36 to your computer and use it in GitHub Desktop.
Identifies if is running from the device or simulator
#include <sys/sysctl.h>
+ (NSString*)hardwareString
{
int name[] = {CTL_HW,HW_MACHINE};
size_t size = 100;
sysctl(name, 2, NULL, &size, NULL, 0); // getting size of answer
char *hw_machine = malloc(size);
sysctl(name, 2, hw_machine, &size, NULL, 0);
NSString *hardware = [NSString stringWithUTF8String:hw_machine];
free(hw_machine);
return hardware;
}
+ (BOOL)isSimulator
{
BOOL simulator = NO; // default NO for Mac OSX
#if TARGET_OS_SIMULATOR || TARGET_OS_IOS || TARGET_OS_TV
NSString *hardware = [self hardwareString];
simulator = [hardware isEqualToString:@"x86_64"];
#endif
return simulator;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment