How to differentiate between iphone4 and iphone 3

前端 未结 9 1385
情歌与酒
情歌与酒 2020-11-28 20:28

I am trying to build a game for the iphone using cocos2d engine. I wanted to know how can I tell a difference whether the user is using iphone 4 or iphone 3 as I wanted to l

9条回答
  •  萌比男神i
    2020-11-28 20:59

    Checking the scale property is not sufficient, as on iPad 3.2 in 2x mode, the scale property exists and will return 2.0, but we know that device does NOT have a Retina display.

    I've created at category on UIScreen to do this. For a more detailed explanation, see my answer to Detect Retina Display. Here's the code:

    @interface UIScreen(ZBScreenRetinaAdditions)
    
    // Returns YES if this is a Retina display.
    - (BOOL)zb_isRetina;
    
    @end
    
    @implementation UIScreen(ZBScreenRetinaAdditions)
    
    - (BOOL)zb_isRetina {
      return [self respondsToSelector:@selector(displayLinkWithTarget:selector:)] && (self.scale == 2.0);
    }
    
    @end
    

    Usage example:

    if ([UIScreen mainScreen] zb_isRetina) {
      // Retina display
    }
    

提交回复
热议问题