Is there a safe way to determine that a device is of a particular model? For example I must know if the device the user uses is a retina display iPod touch.
Asked
Active
Viewed 2,355 times
0
-
1What is the reason you need to know that? It is better to check for individual device capabilities rather than a specific model. – jrturton Aug 15 '12 at 09:23
-
1https://gist.github.com/1323251 – janusfidel Aug 15 '12 at 09:32
2 Answers
8
NSRange r = [[[UIDevice currentDevice] model] rangeOfString:@"iPod"];
float s = [[UIScreen mainScreen] scale];
if (r.location != NSNotFound && s > 1.5f) {
// retina iTouch
}
2
I would probably try something like this:
+(BOOL) isRetinaiPod
{
return [[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"] && [UIScreen mainScreen].scale >= 2.0f;
}
However you can return the device's name with this:
+ (NSString *) deviceName
{
struct utsname u;
uname(&u);
return [NSString stringWithUTF8String:u.sysname];
}

James Webster
- 31,873
- 11
- 70
- 114
-
`struct utsname u; uname(&u); return u;` this is wrong: struct utsname is not an NSString. – Aug 15 '12 at 10:54
-
Thanks for the correction. So it is. My code was working without that, but I'm quite unsure why! – James Webster Aug 15 '12 at 12:28
-
maybe you didn't ever call that method - if you had called it, it would have crashed with a segfaul. :) – Aug 15 '12 at 12:30
-
I was actually returning `@(u.machine)`. Copy error. I had amended from what I actually use (I cache the value) – James Webster Aug 15 '12 at 12:33
-