How can I differentiate iPad and iPhone programmatically?

Possible duplicate:
The best way to programmatically detect iPad / iPhone hardware

How can I programmatically differentiate between iPad and iPhone?

+4
source share
1 answer

It seems to me that the question is a duplicate, but I will try to talk about everything that I know about the type of device and the detection of the version of iOS.

There are several methods based on what information you want to receive, whether it is only the type of device (iPhone, iPod or iPad) or the version of iOS.


Here is the code to determine the type of device (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 the iOS version detector:

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


And the OS detector for the 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 


In addition, no one forbids us to use

 #ifdef __IPHONE_OS_VERSION_MIN_REQUIRED > 40000 //this part of code will be running on devices with os iOS4+ #endif 
+2
source

All Articles