iOS 8.x alternative to detect iPhone 5s, using [UIScreen mainScreen].bounds.size.height == 568.0

857 views Asked by At

In iOS versions prior to iOS 8, to check whether the device is iPhone 5/iPhone 5s, checking [UIScreen mainScreen].bounds.size.height == 568.0 was enough. But in iOS 8.x onwards, this check may fail as the bounds are now orientation dependant. I need a solution to identify the iPhone 5s, 6 and 6+ devices without checking the iOS version.

2

There are 2 answers

3
AudioBubble On BEST ANSWER

I was able to detect the devices using the following macros. This will be useful if you want identify the device, to perform some update on views(like updating frames on orientation changes). If you exactly want the device model/make, use this link (ios iphone get device model and make?) instead.

#define IS_IPHONE       ((int)(MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)) == 480)
#define IS_IPHONE5      ((int)(MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)) == 568)
#define IS_IPHONE6      ((int)(MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)) == 667)
#define IS_IPHONE6PLUS  ((int)(MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)) == 736)
7
l0gg3r On

You can check if

[UIScreen mainScreen].bounds.size.height == 568.0   

and [UIScreen mainScreen].scale to identify iPhone 6 and 6+

Note that this will not work if application is working on "zoomed" mode.
In this case iPhone 6 and 6+ will give scale 2.0