Search code examples
objective-cios8iphone-5boundsmainscreen

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


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.


Solution

  • 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)