Is this the right way to detect an iPad?

Can I use the following code to determine if my application is running on an iPad? My application should run on iOS 3.0 or higher.

if([[[UIDevice currentDevice] model] isEqualToString:@"iPad"]){ //Do iPad stuff. } 
+10
ios objective-c ipad
Dec 31 '10 at 2:39
source share
2 answers

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

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

In earlier versions of iOS, you can return to your code, namely:

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

This approach is compatible with porting in the sense that if Apple releases another iPad next year, the name of the model may change, but the word "iPad" will certainly be somewhere inside the line.

+28
Dec 31 '10 at 2:43
source share

Nope. Do this instead:

 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // ... } 
+5
Dec 31 '10 at 2:42
source share



All Articles