I want to get iphone device type if it is iphone 2 or 3G or 4 in xcode 4.0.
Is there any way to get it?
If it is, please tell me.
Caleb is right, you shouldn't check for device type, but for functionality. For example, you can check whether the device supports multitasking like so:
UIDevice *device = [UIDevice currentDevice];
if ([device respondsToSelector:@selector(isMultitaskingSupported)] && [device isMultitaskingSupported]) {
// ...code to be executed if multitasking is supported.
// respondsToSelector: is very useful
}
If you must, you can check the iOS version, but know this is not a substitute for checking whether an object respondsToSelector:
.
#define IOS4_0 40000
// You'd probably want to put this in a convenient method
NSArray *versions = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
NSInteger major = [[versions objectAtIndex:0] intValue];
NSInteger minor = [[versions objectAtIndex:1] intValue];
NSInteger version = major * 10000 + minor * 100;
if (version >= IOS4_0) {
// ...code to be executed for iOS4.0+
}
As far as I know, there is no documented way to check the device model.