Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-processor directive to detect iPad

I declare some constants in a header file which need to be different depending on whether it is an iPad or an iPhone app. How would I do this?

i.e.

#ifdef ISIPAD
static NSString myconst = @"ipad!";
#else
static NSString myconst = @"iphone!";
#endif
like image 906
Chris James Avatar asked Oct 20 '25 13:10

Chris James


1 Answers

If you're writing an universal app, you can't do a compile time check since the compiler generates one executable for both the iPhone and the iPad. If you've got separate apps for iPhone and iPad (with a shared codebase), why not just #define ISIPAD appropriately yourself. Otherwise, you have to do a check at runtime.

You could make them global variables that get initialized when your app starts up by checking to see which device you're running on then setting them appropriately.

like image 181
Andrew Madsen Avatar answered Oct 22 '25 03:10

Andrew Madsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!