2

Possible Duplicate:
How to deal with iPhone 5 screen size?

So with the release of iPhone 5 today and a larger screen height, how do we accommodate for different screen sizes across the different iPhone variants in our apps. I understand that apps which are not updated for iPhone 5 will be "letter boxed", but what about backwards compatibility?

Is there a way to check whether the app is running on an iPhone 3, 4 or 5?

Community
  • 1
  • 1
rosst400
  • 563
  • 2
  • 7
  • 19
  • I'd say this question is a superset of that question in that its asking how to determine device version, not just screen size. – Shizam Sep 12 '12 at 23:33
  • Sure. By checking for the device version just to do different things only because the screen size is different is not the right approach then: if you have code that must be different because the screen size is different, you should check the screen size, not the hardware model and make some assumptions on its screen size. (actually the user may also use an external screen with arbitrary resolution too to display the content of its iPhone…) – AliSoftware Sep 12 '12 at 23:42

2 Answers2

6

You normally don't need that, because checking the hardware is not the right approach.

If you need to base decisions in your app on the screen size, like accomodate to the screen size for your UI, you should… test the screen size, not make some conditions on the hardware. Always test what is really necessary.

Use [UIScreen mainScreen].bounds for that (as you should always have done). Note that even before iPhone 5, one could plug its iPhone on a videoprojector or external screen and display its app on a screen with different resolution than the iPhone. That's why I hope that you never use magic numbers in your code (And if you did, you know why it's bad now ;)) and was already using constants or asking at runtime for the size of your screen.


Anyway, to accomodate for different screen sizes, if you configured your autoresizing mask correctly in your views, your applications will resize automagically. You just need to provide a Default-h568@2x.png launch image and your app will take the full size of the 4" screen.

Moreover, starting iOS6, you will be able to use AutoLayout to do finer constrainted layout of your views. See the WWDC'12 videos sessions that explains it in detail.

AliSoftware
  • 32,623
  • 6
  • 82
  • 77
2

Checkout the UIDevice-Hardware extension, it was even recently updated to add support for the iPhone 5.

Shizam
  • 9,627
  • 8
  • 51
  • 82