开发者

How can I programmatically determine if my app iPad or iPhone

The point of my question is to be able to dynamically include / exclude code depending on which device is used i need some thing link

#if (TARGET_IPHONE_SIMULATOR)

or

开发者_Go百科

`#if (TARGET_OS_IPHONE)

but to specify if device is an ipad or iphone


I defined two macros in my _prefix.pch file to make it even easier (and more readable) throughout my code, so you can do:

if (iPad) 

or

if (iPhone)

Here's the code:

#ifndef iPad
    #define iPad    (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#endif
#ifndef iPhone
    #define iPhone  (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)
#endif


It's not conditional compilation, but:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    // iPhone Code
} else {
    // iPad Code
}

Which is just a macro for UIDevice's -userInterfaceIdiom method.


Use UI_USER_INTERFACE_IDIOM()

It returns UIUserInterfaceIdiomPhone or UIUserInterfaceIdiomPad

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜