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:
No comments:
Post a Comment