Created
November 28, 2013 21:37
-
-
Save kluivers/7698470 to your computer and use it in GitHub Desktop.
Get the model identifier for the current device (on iOS or Mac)
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/types.h> | |
#include <sys/sysctl.h> | |
#if TARGET_OS_IPHONE | |
char *propertyName = "hw.machine"; | |
#else | |
char *propertyName = "hw.model"; | |
#endif | |
size_t size; | |
// Mac: use 'hw.model'. On iOS use 'hw.machine' | |
sysctlbyname(propertyName, NULL, &size, NULL, 0); | |
char *model = malloc(size); | |
sysctlbyname(propertyName, model, &size, NULL, 0); | |
// model identifier as NSString | |
NSString *modelIdentifier = [NSString stringWithCString:model encoding:NSUTF8StringEncoding]; | |
free(model); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment