How can I programmatically (Objective-C) whether an iPad has a Retina display?
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && [[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [UIScreen mainScreen].scale > 1)
{
// new iPad
}
As other posters have answered, you should check for features rather than models. However, in the few obscure cases where you might want to identify a particular model, you can use the hw.machine sysctrl as follows. Note that if you can't identify the model, it's most likely because your code is running on a new model, so you should do something sensible in that case.
#include <sys/types.h>
#include <sys/sysctl.h>
// Determine the machine name, e.g. "iPhone1,1".
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0); // Get size of data to be returned.
char *name = malloc(size);
sysctlbyname("hw.machine", name, &size, NULL, 0);
NSString *machine = [NSString stringWithCString:name encoding:NSASCIIStringEncoding];
free(name);
Now you can compare "machine" against known values. E.g., to detect iPad (March 2012) models:
if ([machine hasPrefix:@"iPad3,"]) NSLog(@"iPad (March 2012) detected");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With