tags:

views:

65

answers:

1

Possible Duplicate:
Best way to programmatically detect iPad/iPhone hardware

How can I differentiate the iPad and iPhone programmatically?

A: 

It seems for me that the question is a duplicate, but I'll try to brief all I know about device type and iOS version detection.

There are several methods based on which information you want to receive, whether it just device type (iPhone, iPod or iPad) or iOS version.


Here is code for detecting device type (returns i386 in case of Simulator):

#import <sys/utsname.h>

+ (NSString *)getDeviceType {
  struct utsname systemInfo;
  return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8Encoding];
}


And here is iOS version detector:

+ (float)getOSVersion {
  return [[[UIDevice currentDevice] systemVersion] floatValue];
}


And OS detector for compiler:

#ifdef __IPHONE_4_0
  //this part of code will be running on devices with os iOS4+
#else
  //this part of code will be running on devices with os _UNDER_ iOS4+
#endif


Also, nobody proibits us to use

#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED > 40000
   //this part of code will be running on devices with os iOS4+
#endif
NR4TR
`NSStrung` - for when your strings are out of date. ;P
deceze
Oh, sorry, I've typed by heart, not copypasted. Corrected :)
NR4TR
How are COMPILER checks going to help you at RUNTIME?
JUST MY correct OPINION
early morning, need coffee
NR4TR
Is getting the OS version a good idea? It seems to me that this would change over time and when they bring the iPad in line with the iPhone iOS4, will be meaningless in terms of detecting what hardware is in use. It looks like the first option might be the best as it actually addresses the hardware type, not the OS.
Derek Clarkson
You're right, but when we talk about the application that could be launched on different types of iOS, the problem of iOS detection becomes evident, especially knowing that some features of them behaves differently. The question was rather abstract so I thought it would be useful to provide user456920 with some additional info.
NR4TR