Created
July 20, 2016 14:13
-
-
Save priore/73d59a4f565e95189b03c0d2ca923f36 to your computer and use it in GitHub Desktop.
Identifies if is running from the device or simulator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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