Setup an app to detect OS ver. and iPhone or iPad
- How can I detect whether my app is running on an iPhone or iPa开发者_高级运维d, and what iOS 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?
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.
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
精彩评论