0

How can I make a conditional cases based on the model of the iPhone (not of iOS version) like so?

int myResolution = 10;

if ( model >= iPhone3GS ) {
    myResolution = 100;
}

if ( model >= iPhone4 ) {
    myResolution = 120;
}

if ( model >= iPhone5 ) {
    myResolution = 200;
}

Basically so I can quickly set the resolution for some custom OpenGL drawing to manually tweak the performance.

Ross
  • 14,266
  • 12
  • 60
  • 91
  • Read the screen size. – dasdom Feb 20 '13 at 13:58
  • @dasdom 3G and 3GS have the same screen size. So does the iPhone 6 (well, maybe) – Ross Feb 20 '13 at 13:59
  • check this question http://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk – jamapag Feb 20 '13 at 14:00
  • @jamapag thanks, but it doesn't really allow for `model >= iPhone5` to be future proof. I though this would be quite a common task... – Ross Feb 20 '13 at 14:03
  • Have a look at this: http://stackoverflow.com/questions/3339722/check-iphone-ios-version –  Feb 20 '13 at 14:07
  • You are taking the wrong approach. It sounds like you wish to adjust the resolution based on the performance of the device. Instead of hardcoding `myResolution` based on the device model, do a quick timing test at the start of the app. See how long it takes to perform a fixed calculation or iterate through a loop. Calculate an appropriate resolution based on the result. This way your app adapts to any device. – rmaddy Feb 20 '13 at 17:47
  • @maddy I agree. However, this is a bit of a quickie whilst polishing up a project. – Ross Feb 20 '13 at 17:55

1 Answers1

1

Check the comments here: http://www.cocos2d-iphone.org/forum/topic/8107

They implement a DeviceDetection class to perform this task using this approach:

NSString *model= [[UIDevice currentDevice] model];
struct utsname u;
uname(&u);
NSLog(@"%@",u.machine);
apascual
  • 2,970
  • 1
  • 20
  • 32