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.
}
Join Stack Overflow to learn, share knowledge, and build your career.
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.
}
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.
Nope. Do this instead:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// ...
}
UI_USER_INTERFACE_IDIOM()
defined. It's a macro, and on earlier OS versions it devolves to always return UIUserInterfaceIdiomPhone
. If you're using an older SDK, you won't be able to do iPad-specific development anyway as you won't be able to enable iPad targetting.
– Jonathan Grynspan
Dec 31 '10 at 2:44