iPhone Developer Tips Stats: Past 30 days - Pageviews: 88,424 Visitors: 61,675 Thank you everyone! Let's shoot for 100,000 by May. Pass it on...
|
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
One Response 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"];
}