Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this the proper way to detect an iPad?

Can I use the following code to detect if my app is running on iPad? My app needs to run on iOS 3.0 or higher.

if([[[UIDevice currentDevice] model] isEqualToString:@"iPad"]){
  //Do iPad stuff.
}
like image 835
Moshe Avatar asked Dec 31 '10 02:12

Moshe


People also ask

Can iPad's be tracked?

To find your device, sign in to iCloud.com/find. Or use the Find My app on another Apple device that you own. If your iPhone, iPad, or iPod touch doesn't appear in the list of devices, Find My was not turned on. But you can still protect your account if Find My was not turned on.

How do you spot a fake iPad?

To check if it is really not a fake Apple Device you can do the following: selfsolve.apple.com - input the serial number here it will show you some information about the device THE MODEL sometimes Year Released!


2 Answers

Use the UI_USER_INTERFACE_IDIOM() macro on iOS >= 3.2:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   //device is an iPad.
}

On earlier versions of iOS, you can fall back to your code, namely this:

NSRange ipadRange = [[[UIDevice currentDevice] model] rangeOfString:@"iPad"];
if(ipadRange.location != NSNotFound) {
  //Do iPad stuff.
}

This approach is forward-compatible in the sense that if next year Apple released a different iPad, the model name might change, but the word "iPad" will definitely be somewhere inside the string.

like image 177
Jacob Relkin Avatar answered Oct 21 '22 11:10

Jacob Relkin


Nope. Do this instead:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    // ...
}
like image 5
Jonathan Grynspan Avatar answered Oct 21 '22 09:10

Jonathan Grynspan