0

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.

Proud Member
  • 40,078
  • 47
  • 146
  • 231

2 Answers2

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
  • Ah so that's fine :) Yes, copy errors are *annoying*, happened to me also. –  Aug 15 '12 at 12:38