Checking iOS for device

For Universal apps to check which iOS device I’m using at the moment I check for the screen width and if is bigger than X I make a decision, so far it works just fine but I wonder if there another OF constant to facilitate this check process, I thinking something like, OF_IOS_DEVICE_IPHONE or OF _IOS_DEVICE_IPAD then I can do something like

  
if ( OF_IOS_DEVICE_IPAD ) {  
  // use ipad images  
}  
else {  
  // use iphone images  
}  

Hope it makes sense

Hey Ricardo

I’m looking into this at the moment too. I found this earlier:

  
  
if (ofxiPhoneGetDeviceType() == OFXIPHONE_DEVICE_IPHONE)  
    // iPhone stuff  
else if (ofxiPhoneGetDeviceType() == OFXIPHONE_DEVICE_IPAD)  
    // iPad stuff  
      
  

You can also do the following to return the device type as a string:

  
  
NSString *model = [[UIDevice currentDevice] model];  
NSLog(@"Current device model: \"%@\"", model);  
  

If you want the device revision (iPhone3, 4 etc) you can use ofxiPhoneGetDeviceRevision():

Hi guys I don’t have the latest openFrameworks installed so I don’t know what’s going on in your case

you might want to test if it actually works on the devices

in my version of OF it doesn’t because it’s just an enum type:

  
enum ofxiPhoneDeviceType {  
	OFXIPHONE_DEVICE_IPHONE,  
	OFXIPHONE_DEVICE_IPODTOUCH,  
	OFXIPHONE_DEVICE_IPAD  
};  
  

that then it is checked by a caseInsensitiveCompare fucntion

  
  
ofxiPhoneDeviceType ofxiPhoneGetDeviceType() {  
	if([[[UIDevice currentDevice] model] caseInsensitiveCompare:@"iPhone"])  
		return OFXIPHONE_DEVICE_IPHONE;  
	else if([[[UIDevice currentDevice] model] caseInsensitiveCompare:@"iPod"])  
		return OFXIPHONE_DEVICE_IPODTOUCH;  
	else  
		return OFXIPHONE_DEVICE_IPAD;  
}  

in short what OF is doing is:

  
            NSLog([[UIDevice currentDevice] model]);  
  

and then comparing the NSString. this doesn’t work on the simulator for example because the simulator returns iphone simulator

so it will always return wrong. (in the case of 007) i don’t know if they fixed it on new versions.
but I don’t think they support iphone5 anyways…

so heres what you could do if you want to:

you should be doing a comparison using screen resolution.

This is important because in reality what you want to check is if the iphone or ipod is retina …or is it iphone5 screen.

with these 3 parameters you cover all apple devices. (up to this date) there is no need to know if its ipod2 or 3 or whatever.

what matters is RETINA, NON RETINA ipad NOT ipad OR IPHONE5

so in case you are interested I prepared a small universal example with everything adjusted on xcode (icons screeshots retina settings etc)

you can either write one code and let everything be scaled up to fit each device like in the example

or use :

  
if (ofxGetDeviceType()== APPLE_DEVICE_IPHONE_RETINA) {  
    //"iphone4 iphone4s,ipod touch with retina screens";  
          
    }else if(ofxGetDeviceType()== APPLE_DEVICE_IPHONE_NONRETINA ){  
      
    //"older iphones iphone3gs old ipods etc";  
          
    }else if(ofxGetDeviceType()== APPLE_DEVICE_IPHONE_5 ){  
       //"iphone5 new gen ipod touch with wider screen";  
          
          
    }else if(ofxGetDeviceType()== APPLE_DEVICE_IPAD_RETINA ){  
        //"ipad 3 with retina// new smaller ipad";  
          
    }else if(ofxGetDeviceType()== APPLE_DEVICE_IPAD_NONRETINA ){  
        //"ipad 2 older ipads without retina screen";  
          
    }  
  

here is the project:
http://www.2shared.com/file/gXDdyHQv/uofImageExample.html

go ahead and run it on multiple devices to see how it works.

it also includes a universal image object so you just load one path and it loads images according to device automatically… (see example to see what I am talking about)

Great tips guys thanks a lot!