1

Possible Duplicate:
Determine device (iPhone, iPod Touch) with iPhone SDK
iPad 2 detection

Please guide me on how to detect ipad and ipad 2 at runtime on real device.. I want to load different images to both handsets due to performance issue.

Thanks in advance

Community
  • 1
  • 1
user1088267
  • 107
  • 1
  • 5

2 Answers2

5

Easiest and shortest way is to check for a camera, as said in iPad 2 detection :

BOOL isIPad2 = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
            [UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]);

Or even simpler: BOOL isiPad2 = [[self platform] isEqualToString:@"iPad2,1"]; Remember that the string can be iPad2,2 and iPad2,3 as well.

Community
  • 1
  • 1
Emil
  • 7,220
  • 17
  • 76
  • 135
1
- (NSString *)machine {
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    free(machine);
    return platform;
}
  • iPad 1 : @"iPad1,1"
  • iPad 2 : @"iPad2,1"
Niko
  • 2,543
  • 1
  • 24
  • 29
  • Thank Niko.. it works :), but somewhere I read for IPAD 2 sometime you can get iPad2,1 or iPad2,2 or iPad2,3 (depend on operator). Any idea what kind of different string i need to check for iPad and iPad 2 – user1088267 Dec 08 '11 at 22:52
  • If that is so, you can check for iPad2,x string doing this : NSRange range = [theMachineString rangeOfString:@"iPad2" options:(NSAnchoredSearch | NSCaseInsensitiveSearch]]; if (range.length > 0) {NSLog(@"Im a an iPad2");} – Niko Dec 09 '11 at 07:51