Is Application Running on iPhone or iPod touch

If you ever need to know whether your application is running on an iPod touch or an iPhone, the answer is as close as this one line of code:

NSString *deviceType = [UIDevice currentDevice].model;

To get the model of the device as a localized string:

NSString *deviceType = [UIDevice currentDevice].modellocalizedModel;
NSLog(@"type: %@", deviceType);

One use could be to customize messages shown within your applications, for example:

float version = 1.1;
...
NSString *deviceType = [UIDevice currentDevice].model;
NSLog(@"Your %@ has version %2.1f of Today's Horoscope installed.", 
    deviceType, version);

Here’s the output from both of the code snippets is shown below:

  1. Have you figured out how to get which version of the iPhone returned i.e 3g or 3GS? [UIDevice currentDevice] doesn’t seem to store that information.

Comments are closed.