Check If App Is Running On An iPad - Online Free Computer Tutorials.

'Software Development, Games Development, Mobile Development, iOS Development, Android Development, Window Phone Development. Dot Net, Window Services,WCF Services, Web Services, MVC, MySQL, SQL Server and Oracle Tutorials, Articles and their Resources

Friday, March 30, 2012

Check If App Is Running On An iPad

To check if your app is running on an iPad, there is a much easier way.

Check the userInterfaceIdiom property of the device to get the information you need:

  - (BOOL)isDeviceiPad {   BOOL iPadDevice = NO;     // Is userInterfaceIdiom available?   if ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)])   {     // Is device an iPad?     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)       iPadDevice = YES;   }     return iPadDevice; }
As noted in the comments below, Apple provides a macro to accomplish the same task. Here is the full definition from the UIDevice.h header file:

  #define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)
Thanks for the heads up on this.

2 comments: