如何在运行时单独识别ipad 1和ipad 2

时间:2011-12-08 18:08:55

标签: iphone ipad cocos2d-iphone ipad-2

  

可能重复:
  Determine device (iPhone, iPod Touch) with iPhone SDK
  iPad 2 detection

请指导我如何在运行时在真实设备上检测ipad和ipad 2.由于性能问题,我想为两部手机加载不同的图像。

提前致谢

2 个答案:

答案 0 :(得分:5)

最简单和最短的方法是检查相机,如iPad 2 detection中所述:

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

甚至更简单:     BOOL isiPad2 = [[self platform] isEqualToString:@"iPad2,1"]; 请记住,字符串也可以是iPad2,2iPad2,3

答案 1 :(得分: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”