如何区分iphone4和iphone 3

Ank*_*kur 43 ios ccsprite

我正在尝试使用cocos2d引擎为iphone构建游戏.我想知道如何区分用户是使用iphone 4还是iphone 3,因为我想加载iphone4的高分辨率图形和iphone 3的低分辨率.我知道我是否使用@ 2x.png如果我正在使用iphone 4,则图像文件名UIImage的末尾会自动加载高分辨率图像,但对于游戏,我使用cocos2d引擎的CCSprite类来加载图形.

我真的很感激回复.

此致,Ankur

Tom*_*ing 123

您可以检查屏幕的比例.

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2){
    //iPhone 4
}
Run Code Online (Sandbox Code Playgroud)

  • 但是,如果你在2倍变焦的iPad上,那么提供更高分辨率的图形是不是一个很好的奖励呢? (21认同)
  • 实际上,当它处于2倍变焦模式时,iPad的比例为2. (3认同)
  • 请注意,OS 3.2中的iPad上也可以使用缩放比例,而不仅仅是iOS 4上的缩放比例. (2认同)

Wil*_*ter 12

用于检测包括新iPad在内所有设备上的视网膜显示

    +(BOOL)isRetinaDisplay {
    // since we call this alot, cache it
    static CGFloat scale = 0.0;
    if (scale == 0.0) {
        // NOTE: In order to detect the Retina display reliably on all iOS devices,
        // you need to check if the device is running iOS4+ and if the 
        // [UIScreen mainScreen].scale property is equal to 2.0. 
        // You CANNOT assume a device is running iOS4+ if the scale property exists,
        // as the iPad 3.2 also contains this property.
        // On an iPad running iOS3.2, scale will return 1.0 in 1x mode, and 2.0
        // in 2x mode -- even though we know that device does not contain a Retina display.
        // Apple changed this behavior in iOS4.2 for the iPad: it returns 1.0 in both
        // 1x and 2x modes. You can test this yourself in the simulator.
        // I test for the -displayLinkWithTarget:selector: method on the main screen
        // which exists in iOS4.x but not iOS3.2, and then check the screen's scale:

        if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && 
            ([UIScreen mainScreen].scale == 2.0)) {
            scale = 2.0;
            return YES;
        } else {
            scale = 1.0;
            return NO;
        }   

    }
    return scale > 1.0;
}
Run Code Online (Sandbox Code Playgroud)

相信:Adriano Paladini http://developer.appcelerator.com/question/133826/detecting-new-ipad-3-dpi-and-retina


Wri*_*sCS 5

- (NSString *) platform  
{  
    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];  
    free(machine);  
    return platform;  
}  

- (NSString *) platformString  
{  
    NSString *platform = [self platform];  
    if ([platform isEqualToString:@"iPhone1,1"]) return @"Original iPhone";  
    if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";  
    if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3G[S]"; 
    if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";   
    return @"Unknown";  
}  
Run Code Online (Sandbox Code Playgroud)