Skip to content

Instantly share code, notes, and snippets.

@lbrndnr
Forked from steipete/gist:1239338
Created September 24, 2011 14:38
Show Gist options
  • Save lbrndnr/1239394 to your computer and use it in GitHub Desktop.
Save lbrndnr/1239394 to your computer and use it in GitHub Desktop.
PSIsCrappyDevice
BOOL PSIsCrappyDevice() {
static BOOL isCrappyDevice = YES;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [[NSString alloc] initWithCString:machine];
free(machine);
isCrappyDevice = !(![platform hasPrefix:@"iP"] || [platform hasPrefix:@"iPhone3"] || [platform isEqualToString:@"iPod4,1"] || [platform hasPrefix:@"iPad2"]);
[platform release];
});
return isCrappyDevice;
}
@steipete
Copy link

It's usually not a good idea to explicitely check for STRINGS for a platform. Much better to search for aspects. You want your code be future proof.

@myell0w
Copy link

myell0w commented Sep 25, 2011

While checking for strings might not be a good idea, checking for aspects might break as easily. While it might never happen, just imagine the next iPad having neither Retina nor Camera, or a new device falling into this category - checking for aspects breaks and treats this device as a crappy device.

@steipete
Copy link

How high are the odds for apple DOWNGRADING from retina? If so, it sure must be a crappy device ;)
But true... neither is perfect.

@myell0w
Copy link

myell0w commented Sep 25, 2011

Not all current devices have retina, so I wouldn't consider it a downgrade. There might be room for a cheaper model of the next iPhone/iPad, and we never know the specs. There's definitely neither of the methods perfect, I'm just not sure what's easier to break (so which method I should add to iOSKit :) ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment