- How can I detect whether my app is running on an iPhone or iPad, and what OS version it is running?
- Can I use pre-processor macros in a similar fashion to
#if _OS4.0
or#if IPAD
or something of the sort? - Is this kosher, or should I just make separate builds for submission?
views:
129answers:
3
A:
The UI_USER_INTERFACE_IDIOM() can be used to detect the device. Possible return values are:
- UIUserInterfaceIdiomPhone
- UIUserInterfaceIdiomPad
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {}
There's also the __IPHONE_3_2
define that can help:
#ifndef __IPHONE_3_2
/* ... */
#elif
/* ... */
#endif
Macmade
2010-07-21 16:13:26
This is very helpful thank you. I've run into some other issues though. When I try to build with my iPad target, all of the code for my iAd stuff breaks.
devMeSilus
2010-07-21 16:43:34
+2
A:
Generally using features based on OS version is bad practice.
As offered, use UI_USER_INTERFACE_IDIOM() whenever possible. Also use:
Class qlPreview = NSClassFromString(@"QLPreviewController");
and
UIScreen *mainScreen = [UIScreen mainScreen];
if([mainScreen respondsToSelector:@selector(scale)]){
NSLog(@"screen scale: %f",[mainScreen scale]);
}
However, sometimes you can't avoid it checking for system version.
christo16
2010-07-21 16:52:08