Check if the user device is an ipad or iphone / ipod, the difference between the two methods

I read Apress - Beginning iPad Development for iPhone Developer Mastering the iPad SDK , and in one chapter I read about checking the device and writing the author:

β€œAlthough you may just need to check the type of user device or version of the operating system, Apple is constantly releasing new devices and versions of iOS, it’s not. The best approach is to check for exclusive iPad classes using NSClassFromString. If you pass the class name iPad for example, UISplitViewController in NSClassString and the actual object is returnet, you will find out that the user device is an iPad .. "

I do not understand why just check the type of device, for example:

  NSString *device = [[UIDevice currentDevice] model]; if ([device rangeOfString:@"iPad"].location != NSNotFound ) { isIPad = true; } else isIPad = false; 

Worse than checking ipad classes?

0
objective-c iphone device ipad
source share
2 answers

The way Apple tests its own examples and when you launch the new universal app looks like this:

 -(BOOL) isiPad { return UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad; } 

And the reason why using the model is probably bad is because you are simply using string comparison. Although I doubt that they will change it, you never know when they can decide to change the string returned by [[UIDevice currentDevice] model] to a model number or something else.

+7
source share

maybe this method will help you

 -(int)CheckDevice { return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) ? 1 :([[UIScreen mainScreen] bounds].size.height == 568) ? 5 :4; } 

he returns

  • 1 for ipad
  • 4 for iphone 4
  • 5 for iphone 5
-one
source share

All Articles