How do I use different images, depending on iOS device type?

6.1k views Asked by At

I want to use different images in my iPhone application, depending on whether the current device is an iPhone 3G, iPhone 4, or iPad. I've tried getting the screen resolution (size) of the device, but it always returns 320 X 480 for the different iPhones.

How do I determine which type of device I'm running on so that I can provide the correct images?

I do not want to get the iPhone OS version.

3

There are 3 answers

0
Mitesh Khatri On BEST ANSWER
1
macserv On

If you want this info for the purposes of selecting the proper graphics for your resolution, then middaparka's answer is what you're looking for.

However, if you happen to need device model or resolution info for a different purpose, then UIDevice and UIScreen may be what you want.

NSString *myDeviceModel = [[UIDevice currentDevice] model];
CGRect    myScreenSize  = [[UIScreen mainScreen] bounds].size;
2
John Parker On

There's most likely no need to do what you're attempting to do, as iOS has built in support for loading images at the appropriate size for the iPhone (retina and pre-retina resolutions) and iPad.

Read the Resource Programming Guide (specifically the "Specifying High-Resolution Images in iOS" and "iOS Supports Device-Specific Resources" section) and the iOS Application Programming Guide for more information.

Incidentally, both the pre and post retina iPhone/Pods have a point resolution of 320 X 480. Apple distinguishes between point sizes (resolution independent) and pixel size to help things along the way.