从埃里卡苏丹:
- (NSString *) platform
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
/*
Possible values:
"iPhone1,1" = iPhone 1G
"iPhone1,2" = iPhone 3G
"iPhone2,1" = iPhone 3GS
"iPhone3,1" = iPhone 4
"iPod1,1" = iPod touch 1G
"iPod2,1" = iPod touch 2G
*/
NSString *platform = [NSString stringWithCString:machine];
free(machine);
return platform;
}
或者,如果你只需要检测,如果它是一个高分辨率的屏幕,你可以使用:
UIScreen *screen = [UIScreen mainScreen];
BOOL isHighRes;
if ([screen respondsToSelector:@selector(scale)]) {
isHighRes = ([screen scale] > 1);
} else {
isHighRes = NO;
}
你需要什么检测到它呢? – kennytm 2010-07-05 14:22:05
如果使用iPhone 3G/3GS或iPod Touch第二代,我有一些图像需要缩小比例。在其他所有情况下(iPhone 4或iPad),图像必须保持原始大小。在运行时我没有图像,我不得不即时检测设备。 – SpaceDog 2010-07-05 14:30:49
可能模拟器实际上并不模拟这些零件。你必须在开发过程中用#ifdef或类似的东西来伪造它。 – 2010-07-05 15:07:04