Is there a build preprocessor I can use, like #if or #ifdef to check whether my current xcode project is being built for iphone or ipad?
+1
A:
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"]) {
//iPhone
}
else if([deviceType isEqualToString:@"iPod touch"]) {
//iPod Touch
}
else {
//iPad
}
You cannot, as far as I am concerned, use #if or #ifdef to do this but, it is supported because Obj-C is a strict superset of C.
Related: Determine device (iPhone, iPod Touch) with iPhone SDK
thyrgle
2010-09-12 23:58:38
Thats what I was afraid of since they essential run the same applications.
Justin Meiners
2010-09-13 00:03:26
Obj-C is a strict superset of Obj-C???
Alexander Rafferty
2010-09-13 00:05:04
Thanks for the help though. I think I can think of a configuration that I can setup that creates a #define based on this.
Justin Meiners
2010-09-13 00:05:51
@Alexander Rafferty: Oops sorry. Yeah, C is what I meant to say.
thyrgle
2010-09-13 00:06:14
@Alexander Ha I know what he means.
Justin Meiners
2010-09-13 00:06:23
You can't do a compile-time check for a "universal binary" because it's being *built for both*. If you build separate iPad and iPhone apps, then there are many ways, including defining your own compiler macros for the different targets.
tc.
2010-09-13 00:43:52
+6
A:
Some ideas in the comment section of this blog
http://greensopinion.blogspot.com/2010/04/from-iphone-to-ipad-creating-universal.html
Mostly using
UI_USER_INTERFACE_IDIOM()
Such as:
#ifdef UI_USER_INTERFACE_IDIOM()
#define IS_IPAD() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
#define IS_IPAD() (false)
#endif
Lou Franco
2010-09-13 00:08:35