iPhone Developer Tips Visitor Stats: 122,631 Pageviews and 90,229 visitors in the past 30 days.
|
The iPhone SDK includes a singleton of class type UIDevice that you can use to retrieve device specific information (this works equally as well with the simulator).
Available Properties in UIDevice
- uniqueIdentifier – identifier guaranteed to be unique for every device
- name – arbitrary name found in General > About setting on device
- systemName – name of the OS running on the device
- systemVersion – current version of the OS
- model- model, such as ”iPhone” or ”iPod touch”
- localizedModel – same as above using a localized string
Stats for Simulator
This code will list all stats shown above:
NSLog(@"uniqueIdentifier: %@", [[UIDevice currentDevice] uniqueIdentifier]);
NSLog(@"name: %@", [[UIDevice currentDevice] name]);
NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]);
NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]);
NSLog(@"model: %@", [[UIDevice currentDevice] model]);
NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel]);
Running the above on the simulator returns:

Stats for iPhone
The device stats when running on my iPhone:

Comments
3 Responses to “Get iPhone Device Name, Unique Device Identifier (UDID), OS and Model”
Leave Comment
you can get the device model, like iPhone2,1 by using sysctlbyname(), Erica Sadun had a writeup about this at http://arstechnica.com/apple/guides/2009/03/iphone-dev-determining-your-platform.ars
the platform method below will give you @”iPhone2,1″ or whatever the device is
- (NSString *) getSysInfoByName:(char *)typeSpecifier
{
size_t size;
sysctlbyname(typeSpecifier, NULL, &size, NULL, 0);
char *answer = malloc(size);
sysctlbyname(typeSpecifier, answer, &size, NULL, 0);
NSString *results = [NSString stringWithCString:answer encoding: NSUTF8StringEncoding];
free(answer);
return results;
}
- (NSString *) platform
{
return [self getSysInfoByName:"hw.machine"];
}
Is there a way to retrieve the model type, such as 3G, 3GS and 4? I mainly need to know if the device is a 3 or 4 (G or GS isn’t necessary, but would be useful).
The post below shows how to get the device type;
Determine Device Type – 3G or 3GS / iPod First or Second Generation