what is the code to detect whether ios app running in iPhone, iPhone Retina display, or iPad?
NickName:Greg Ask DateTime:2011-08-28T04:51:22

what is the code to detect whether ios app running in iPhone, iPhone Retina display, or iPad?

what is the code to detect whether ios app running in iPhone, iPhone Retina display, or iPad?

Background:

  • for my iPhone application I have defined in XCode target/summary page the specific images for: iPhone launch image, iPhone retina display launch image, iPad portrait & iPad landscape.

  • in the main view there is a UIImageView subview I use for the background image - currently I'm specifying this in XCode (not programmatically) by selecting the image I use for the iPhone launch image.

So I'm asking how to tell which one I'm running within so that in the viewDidLoad I can load the appropriate resolution background image. Then there should be a seamless transition between the background image for app startup, and the background of the app main screen once it's started.

Copyright Notice:Content Author:「Greg」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7217277/what-is-the-code-to-detect-whether-ios-app-running-in-iphone-iphone-retina-disp

Answers
omz 2011-08-27T21:04:03

You can use [[UIDevice currentDevice] userInterfaceIdiom] to determine whether you're running on an iPhone/iPod touch or an iPad.\n\nThere's often no need to determine directly whether you're on a retina display because UIImage handles that automatically when you use imageNamed and append \"@2x\" to your high resolution image file names (see Supporting High-Resolution Screens in the Drawing and Printing Guide for iOS).\n\nIf you really need to know which resolution the screen has, use UIScreen's scale method.",


Luke 2011-08-28T20:22:24

Here's 2 useful class methods that I use, which directly answers your question - which you may want to use further down the line:\n\n+(BOOL)isPad\n{\n#ifdef UI_USER_INTERFACE_IDIOM\n return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;\n#endif\n return NO;\n}\n\n+(BOOL)hasRetinaDisplay\n{\n // checks for iPhone 4. will return a false positive on iPads, so use the above function in conjunction with this to determine if it's a 3GS or below, or an iPhone 4.\n if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2)\n return YES;\n else\n return NO;\n}\n",


Masterfego 2015-03-16T14:53:54

For Swift Solution:\n\n if (UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad) \n {\n // Ipad\n }\n else \n {\n // Iphone\n }\n",


justin 2011-08-27T20:54:01

see @interface UIDevice\n\nas well as the documentation at -[UIImage scale] (although there are better resources, which will likely be posted).",


More about “what is the code to detect whether ios app running in iPhone, iPhone Retina display, or iPad?” related questions

what is the code to detect whether ios app running in iPhone, iPhone Retina display, or iPad?

what is the code to detect whether ios app running in iPhone, iPhone Retina display, or iPad? Background: for my iPhone application I have defined in XCode target/summary page the specific images...

Show Detail

How to show an iPhone app on iPad with retina display graphics?

I have an iPhone app and upgraded the target for iPad in Xcode. But now, the app launches in the upper left corner of the iPad very small only. I want to scale it up to the iPad screen but then use...

Show Detail

Ideals Resolutions for Images in iPhone/iPad & iPhone(Retina)/iPad(Retina)

Can someone tell me what the ideal resolution for images are for an iPhone/iPad and iPhone(Retina)/iPad(Retina). I have pulled these measurements off of the Apple Website and Wikipedia. See Below:

Show Detail

iPad Retina - iPad uses the iPhone retina images

This is a little bit weird. Now, I am developing an app that's universal. However, I don't provide images for the iPad retina (iPad 3 and 4), but still retina images available for the iPhone. Now, ...

Show Detail

iOS iPhone Application running iOS7 Retina graphics for iPad2 and iPad Mini

I've noticed that the iPhone applications running on non-retina devices (iPad 2 and iPad Mini) are now by default rendered at iPhone Retina Graphics (2x) (If the Application has the retina assets).

Show Detail

How to turn on iPhone Retina in iOS Simulator?

I built and ran an iOS 4.3 app in Simulator. It initially brings up an iPhone 4 shell. Although all real iPhone 4s have retina display, this simulated iPhone 4 only has a resolution of 320x480. I ...

Show Detail

Setup an app to detect OS ver. and iPhone or iPad

How can I detect whether my app is running on an iPhone or iPad, and what iOS version it is running? Can I use pre-processor macros in a similar fashion to #if _OS4.0 or #if IPAD or something of the

Show Detail

Are iPhone retina pixels of the same physical dimensions as iPad retina pixels?

I'm designing an app that creates graphics for retina displays. One of the benefits I want to offer to the users is that the graphics designed the iPad app would look exactly the same on the iPhone...

Show Detail

Separate storyboards for iPhone/iPhone Retina/iPad/iPad Retina

I have a question that may sound odd, but being somewhat of a newbie, I am guessing no question is a stupid question... Do I need separate storyboards for all four devices? Right now I have two

Show Detail

Sprite Kit universal app: Same textures for iPhone and non-retina iPad?

Since Sprite Kit / iOS7 only supports iPhone 4 and newer, I don't need non-retina textures on iPhone. So if I have an universal app and want to keep the overall bundle size small, I could use the s...

Show Detail