8

On iPhone5 [[UISCreen mainScreen] bounds].size comes back as 320x480. Why. In all the posts I'm reading, people are saying that it returns the correct screen size. What is going on here? Am I missing something in the .plist file or something?

BTW I am hand coding the GUI, so there is no XIB.

Brooks
  • 2,082
  • 2
  • 18
  • 26
  • 2
    Duplicate of http://stackoverflow.com/questions/12395200/how-to-develop-or-migrate-apps-for-iphone-5-screen-resolution (and many, many others ...) – Martin R Oct 05 '12 at 19:53
  • A bit smarmy and not appreciated. Can you point to a specific answer to my question? Because I read every one of those "many, many others" and not one answered the question I asked. Not to say I didn't overlook something, but perhaps you should read my question again before jumping to that conclusion. – Brooks Oct 05 '12 at 20:13
  • Definitely incorrect on your claim of a duplicate question. The answer to the link you posted lists simply using mainScreen bounds. – Brooks Oct 05 '12 at 20:25
  • If you add a Default-568h@2x.png launch image to the project (as described in http://stackoverflow.com/questions/12395200/how-to-develop-or-migrate-apps-for-iphone-5-screen-resolution) and run on on iPhone 5, then `[[UIScreen mainScreen] bounds].size` returns `(width=320, height=568)`. – Martin R Oct 05 '12 at 20:29
  • That is bizarre. It also seems really dirty. Is there no programmatic way of getting the software to behave correctly? – Brooks Oct 05 '12 at 20:31
  • 2
    There is no other way. You can find the same answer multiple times on SO. – Martin R Oct 05 '12 at 20:37

2 Answers2

30

Unless your app includes a Default-568h.png in it's bundle, it will run inside a 480 point high legacy screen sandbox on the iPhone 5, and can't draw or see any dimensions outside that sandbox.

Note that including this Default-568h.png is only allowed when building an app using Xcode 4.5 and the iOS 6 SDK (or, presumably, later) for submission to Apple's App store.

Added: When building with the iOS 8 SDK (or later) and running the app under iOS 8 (or later), a LaunchScreen.xib will also remove the 480 height sandbox.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • I was missing that. Thanks, saved my bacon. – Duck Oct 31 '12 at 08:10
  • Note that this sandbox isn't a dirty trick, but helpful in creating an app environment where older apps don't crash or display crazy stuff when the user upgrades to an iPhone 5 that the developer could never have tested their app on at the time it was developed. – hotpaw2 Mar 22 '13 at 03:19
  • Dang it I wasted 2 hours of my time on this :( – omygaudio Sep 28 '14 at 05:33
1

It would appear that having a launch image in place is a prerequisite to [[UIScreen mainScreen] bounds] working properly on iPhone5. This is an issue for those of us dependent on design teams for our images. It looks like you just have to hack together a launch image and put it in place.

Is there really no better way? Anyone?

Brooks
  • 2,082
  • 2
  • 18
  • 26
  • 1
    `Default-568h.png` is the way, period. This has been discussed at length both on stackoverflow and on [Apple's own developer forums](https://devforums.apple.com/search.jspa?resultTypes=MESSAGE&peopleEnabled=true&q=Default-568h). Since Apple only cares about app store distribution, and all app store apps must have launch images, Apple has no need to provide another way to enable the 568 pt screen. – rob mayoff Oct 05 '12 at 21:31
  • It does absolutely suck. First of all not having a way to do this from code just seems plain wrong. And secondly it should be perfectly possible to not even use a splash screen. Now I have to integrate a fake "fully black" splash screen just for this to work on one out of the 9 devices targeted. Sheesh. Rant over. – Dev Kanchen Oct 06 '12 at 14:51