I want to identify the device on which my application is installed. That means, when I install the app on the iphone, it should tell me the device information. The information is like, the device is 2G, 3G or 3GS.
Currently I am getting only model, name, systemName, systemVersion of the device.
I want to know the device is 2G , 3G or 3GS.
please help me.
In the past history of Mac programming, this was always considered the wrong question.
What you really need to know is a more specific piece of information. Ask a much more narrow question for each behavioral decision in your code. For example, you may need to know if the device has GPS or not. Another is that you shouldn't decide how to use the OpenGL stack based on what model device it is, but rather on the OpenGL capabilities/extensions information that is provided.
The information you're getting now is from UIDevice, which is an unfortunately poorly designed API. It provides you with exactly the wrong information in the worst possible format -- strings.
Erica Sadun has an extension to UIDevice that may be useful here. It's just a wrapper for sysctlbyname("hw.machine", ...)
. This property is different for each model.
But again, this is usually the wrong question.
This is what I used in my app and it works great
NSString *deviceType = [UIDevice currentDevice].model;
NSLog(@"DEVICE TYPE %@", deviceType);
struct utsname systemInfo;
uname(&systemInfo);
- (NSString *) platformString{
NSString *platform = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
NSLog(@"type ...%@", platform);
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad";
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)";
if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)";
if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)";
if ([platform isEqualToString:@"i386"]) return @"Simulator";
return platform;
}
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With