Objective-C Tips & Trick - Prioregroup.com
[Objective-C] Identifies if is running from the device or simulator
       
back

#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;
}






Copyright © 1996-2018 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.
prioregroup.com