The following could be used to get a C string representing the model of an iOS device
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
This solution is taken from this Objective-C based answer, which also includes a list of what will be stored in machine
. A list of these values can also be found on The iPhone Wiki.
The value for the iPhone 4 is iPhone3,x
, with x
being either 1, 2, or 3, depending on the specific model. The value for the iPhone 6 is iPhone7,x
, with x
being either 1 or 2.