Please consider subscribing to Mobile Developer Tips RSS feed or following us on Twitter
|
|
|
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:

Related posts:
- Is Application Running on iPhone or iPod touch
- Determine Device Type – 3G or 3GS / iPod First or Second Generation
- Getting the iPhone User Name
Comments
6 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"];
}
[Reply]
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).
[Reply]
The post below shows how to get the device type;
Determine Device Type – 3G or 3GS / iPod First or Second Generation
[Reply]
Unfortunately it is deprecated in iOS5.
[Reply]
John Muchow Reply:
November 15th, 2011 at 3:21 pm
I wrote about an alternative here that may be an option for a unique identifier: Determine MAC Address not that the UDID is deprecated.
[Reply]
Using UIDevice, many application developers will create their application privacy setting to download and update new version.
[Reply]