{"id":1943,"date":"2014-09-13T12:01:10","date_gmt":"2014-09-13T19:01:10","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1943"},"modified":"2014-10-08T09:43:32","modified_gmt":"2014-10-08T16:43:32","slug":"1943","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1943","title":{"rendered":"Device types in iOS"},"content":{"rendered":"<p>I sometimes need to know the device type that the app is running on. I use this method in my Utilities class to do it. Updated for the new devices introduced in the fall of 2014.<br \/>\n<pre><code class=\"\u2019smallest\u2019 preserve-code-formatting\">\n+ (NSString *)deviceType {\n&nbsp;&nbsp;&nbsp;&nbsp;NSString *device = nil;\n&nbsp;&nbsp;&nbsp;&nbsp;CGSize screenSize = [[UIScreen mainScreen] bounds].size;\n&nbsp;&nbsp;&nbsp;&nbsp;CGFloat deviceScale = [UIScreen mainScreen].scale;\n\n&nbsp;&nbsp;&nbsp;&nbsp;if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device = @&quot;iPhone Classic&quot;; \/\/ Just in case it doesn&#039;t make it through the conditionals\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Classic has a resolution of 480 \u00d7 320\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( (screenSize.height == 480 || screenSize.width == 480) &amp;&amp; deviceScale == 1.0f ) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device = @&quot;iPhone Classic&quot;;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Retina has a resolution of 960 \u00d7 640\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else if( (screenSize.height == 480 || screenSize.width == 480) &amp;&amp; deviceScale == 2.0f ) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device = @&quot;iPhone Retina35&quot;;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Retina 4&quot; has a resolution of 1136 x 640\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else if (screenSize.height == 568 || screenSize.width == 568 ) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device = @&quot;iPhone Retina4&quot;;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ iPhone 6 has a resolution of 1334 by 750\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else if (screenSize.height == 667 || screenSize.width == 667 ) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device = @&quot;iPhone 6&quot;;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ iPhone 6 Plus has a resolution of 1920 by 1080\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Reported size is 736 x 414\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else if (screenSize.height == 736 || screenSize.width == 736 ) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device = @&quot;iPhone 6 Plus&quot;;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device = @&quot;iPad Classic&quot;; \/\/ Just in case it doesn&#039;t make it through the conditionals\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(deviceScale == 1.0f) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device = @&quot;iPad Classic&quot;;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else if (deviceScale == 2.0f) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device = @&quot;iPad Retina&quot;;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/NSLog(@&quot;The device is %@ scale is %f and the height is %f and width is %f&quot;, device, deviceScale, screenSize.height, screenSize.width);\n\n&nbsp;&nbsp;&nbsp;&nbsp;return device;\n}\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I sometimes need to know the device type that the app is running on. I use this method in my Utilities class to do it. Updated for the new devices introduced in the fall of 2014. + (NSString *)deviceType { &nbsp;&nbsp;&nbsp;&nbsp;NSString *device = nil; &nbsp;&nbsp;&nbsp;&nbsp;CGSize screenSize = [[UIScreen mainScreen] bounds].size; &nbsp;&nbsp;&nbsp;&nbsp;CGFloat deviceScale = [UIScreen mainScreen].scale; &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1943\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Device types in iOS<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1943","post","type-post","status-publish","format-standard","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1943"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1943\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}