I was wondering if it\'s possible to determine what kind of iPhone (for example) the currentdevice is? I know it\'s possible to get the model through
NSString
[[UIDevice currentDevice] model]
just returns iPhone
or iPod
, you don't get the numbers of the model that would let you differentiate between different generations of devices.
Code this method:
#include
...
+ (NSString *)getModel {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *deviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
free(model);
return deviceModel;
}
And call the method [self getModel]
whenever you need the model and you'll get i.e: "iPhone5,1" for the ridiculously thin and speedy iPhone 5.
One good practice is to create a class called Utils.h/Utils.m
and put methods like getModel
there so you can get this info from anywhere in your App simply by importing the class and invoking [Utils getModel];