1

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) {
     ....
}
punkrockbuddyholly
  • 9,675
  • 7
  • 36
  • 69
user1051935
  • 579
  • 1
  • 10
  • 29
  • 3
    duplicate of [Determine device (iPhone, iPod Touch) with iPhone SDK](http://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk) – Sophie Alpert Feb 03 '12 at 16:45

2 Answers2

6

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"])
{
    ...
}
Nick Lockwood
  • 40,865
  • 11
  • 112
  • 103
0

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.

Cliff
  • 10,586
  • 7
  • 61
  • 102
  • That's not the best way to tell if it's an iPod (see my answer) but it is a good example of the feature detection I was talking about, which is better practice in general. – Nick Lockwood Feb 03 '12 at 16:58
  • I agree with @NickLockwood ... not the best way to go about ! – Legolas Feb 03 '12 at 17:06
  • True this is not the best approach for detecting the particular device but overall gives you better forward compatibility. – Cliff Feb 03 '12 at 19:10