Kevin Glier Kevin Glier - 4 months ago 10
Objective-C Question

Preprocessor-IF doesn't work

I'm trying to check with Preprocessor-Ifs if the Device is an iPad. If it is an iPad, I want to define something Devicespecific, but for some reason I can't check in an PP-IF if a PP-Constant is true.

Maybe you got an idea?

#ifdef UI_USER_INTERFACE_IDIOM

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

#else

#define IS_IPAD false

#endif



#if IS_IPAD

#define WIDTH 768
#define HEIGHT 1024

#else

#define WIDTH 320
#define HEIGHT 480

#endif

Tim Tim
Answer

Preprocessor rules are, (surprise, surprise) processed prior to building the app. Since it's an universal app, it doesn't yet know if it's running on an iPad or an iPhone.

Use this:

#ifdef UI_USER_INTERFACE_IDIOM
    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
    #define IS_IPAD false
#endif

#define WIDTH (IS_IPAD ? 768 : 320)
#define HEIGHT (IS_IPAD ? 1024 : 480)