Skip to content

Instantly share code, notes, and snippets.

@kluivers
Created November 28, 2013 21:37
Show Gist options
  • Save kluivers/7698470 to your computer and use it in GitHub Desktop.
Save kluivers/7698470 to your computer and use it in GitHub Desktop.
Get the model identifier for the current device (on iOS or Mac)
#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