I am trying to find a way to detect if the device used is an iPod touch, is there any?
I am using this method for the iPad...
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
....
}
I am trying to find a way to detect if the device used is an iPod touch, is there any?
I am using this method for the iPad...
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
....
}
Why do you want to know? If it's because you want to know if has a camera or can make phone calls etc. then you'd be better off doing this with feature detection (in case Apple make an iPod with a phone in it at some point!) such as Cliff's answer.
If it's for some other reason and you really do just want to know if it's an iPod or iPhone, irrespective of the actual device capabilities, here's how you do it:
if ([[UIDevice currentDevice].model isEqualToString:@"iPod touch"])
{
...
}
A rough hack that I've exploited in the past is to query whether the device can dial a phone#. I forget the syntax offhand but there should be something like
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:+11111"]]) {
//we have an iphone
} else if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
//We have an iPad....
} else {
//We probably have an iPod....
}
Honestly, I prefer this approach over absolute detection because it focuses on capabilities of the device rather than the model. It's better to conditionalize logic based on what the device is capable of rather than on the model because you never know what capabilities will be introduced in future release of iOS devices. For instance, hiding video controls if device type == iPad would have made practical sense just over a year ago but would have limited that functionality when the iPad2 was introduced in a matter of months. If you assume just because the device is an iPod that you should or should not do features X then you will limit functionality on further releases of the product should the capability be added.