开发者

Setup an app to detect OS ver. and iPhone or iPad

  1. How can I detect whether my app is running on an iPhone or iPa开发者_高级运维d, and what iOS version it is running?
  2. Can I use pre-processor macros in a similar fashion to #if _OS4.0 or #if IPAD or something of the sort?
  3. 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜