0

I have an app I designed for 3.5 and 4 inch. I adjusted the items on screen with the following method:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
    //4 inch code

} else {
    //3.5 inch code

}

Then iPhone 6 and 6 plus were released so I had to adjust their screensizes as well. Fortunately the iPhone 6 has the same scale so that worked with the same method. But when it came to the iPhone 6+ it did not work anymore because it is a 3x-scale.

Now this is why I changed my method I used before, to:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if ([UIScreen mainScreen].nativeScale > 2.1) {
    //6 plus

} else if (screenBounds.size.height == 568) {
    //4 inch / iPhone 6 code

} else {
//3.5 inch code

}

Now that works perfectly on all devices BUT the iPhone 4S. It crashes. The log says:

2014-10-17 21:06:31.370 Lichtpunkt[1288:60b] -[UIScreen nativeScale]: unrecognized selector sent to instance 0x17539920 2014-10-17 21:06:31.372 Lichtpunkt[1288:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIScreen nativeScale]: unrecognized selector sent to instance 0x17539920' *** First throw call stack: (0x30b94fd3 0x3b40dccf 0x30b98967 0x30b97253 0x30ae67b8 0x4102b 0x3342fda5 0x3305d2c1 0x33046e3f 0x33121d6d 0x330466f3 0x3304639b 0x3302a03d 0x33029cd5 0x330296df 0x330294ef 0x3302321d 0x30b602a5 0x30b5dc49 0x30b5df8b 0x30ac8f0f 0x30ac8cf3 0x35a21663 0x3341416d 0x18d6b91 0x2c9d1 0x3b91aab7) libc++abi.dylib: terminating with uncaught exception of type NSException

And the problem is that I can not revert the change to the 1st solution since the iPhone 6+ is then not completely adjusted, I tried.

Can anyone help me please?

LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174

1 Answers1

0

[UIScreen nativeScale] is only available under iOS 8.

Which is why it's crashing on iOS 7 & older devices.

You need to come up with an alternative that works on both iOS 8 and older iOS versions that you want to support. There's a few other screen size fetching methods within UIScreen that work all the way back to iOS 2, but then you need to take into account that the height and width get exchanged when the device is moved between portrait & landscape modes.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Oh thanks. This explains why it works in the simulator but not on my iPhone 4S 7.1.1. Do you know one or shall I just implement both, for each size one method (the ios7 compatible one first) or will it still crash? – LinusGeffarth Oct 18 '14 at 04:33
  • Well my app only supports portrait mode so that won't be a problem. Thank you so much! – LinusGeffarth Oct 18 '14 at 04:42