{"id":2506,"date":"2016-06-25T15:29:36","date_gmt":"2016-06-25T22:29:36","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=2506"},"modified":"2018-03-20T13:14:43","modified_gmt":"2018-03-20T20:14:43","slug":"deprecated-ios-methods-rotation","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=2506","title":{"rendered":"Deprecated iOS Methods: Rotation Setup"},"content":{"rendered":"<p>I haven\u2019t updated my code for a while because I wanted to continue to support iOS5 on first generation iPads. Since Apple allows older devices to download older versions of the software, and my code in the App Store appears to be stable, I decided to update the existing code and get rid of deprecated code warnings. (I have 56 deprecated method warnings that I need to get rid of.)<\/p>\n<p>First up is <i>shouldAutorotateToInterfaceOrientation<\/i>. This method, along with <i>shouldAutorotate<\/i> is sprinkled throughout my code because it was required for each view. <\/p>\n<p>The old code, in the AppDelegate.m file, supported iOS 5-9 and looked like this:<br \/>\n<pre><code class=\"preserve-code-formatting\">\n#pragma mark - Handle rotation for different versions of the OS\n- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {\n&nbsp;&nbsp;&nbsp;&nbsp;return YES;\n}\n\n\/\/ iOS 6 and above\n- (BOOL)shouldAutorotate {\n&nbsp;&nbsp;&nbsp;&nbsp;return YES;\n}\n\n- (NSUInteger)supportedInterfaceOrientations {\n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;#ifdef UIInterfaceOrientationMaskAll\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return UIInterfaceOrientationMaskAll;&nbsp;&nbsp;\/\/ iOS6+ method.\n&nbsp;&nbsp;&nbsp;&nbsp;#else\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;\n&nbsp;&nbsp;&nbsp;&nbsp;#endif\n}<\/code><\/pre><\/p>\n<p>I replaced it in the AppDelegate.m with this line:<br \/>\n<pre><code class=\"preserve-code-formatting\">\n- (NSUInteger)supportedInterfaceOrientations {\n&nbsp;&nbsp;&nbsp;&nbsp;return UIInterfaceOrientationMaskAll;\n}<\/code><\/pre><\/p>\n<p><strong>Update 2018-03-20<\/strong><br \/>\nThe current version of Xcode prefers that <em>NSUInteger<\/em> be replaced with <em> UIInterfaceOrientationMask <\/em>.<\/p>\n<p>and removed lots of occurrences of <i>shouldAutorotateToInterfaceOrientation<\/i>.<\/p>\n<p>\u201cIn iOS 6 and iOS 7, your app supports the interface orientations defined in your app\u2019s Info.plist file.\u201d <a href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/UIKit\/Reference\/UIViewController_Class\/index.html#\/\/apple_ref\/occ\/instm\/UIViewController\/shouldAutorotateToInterfaceOrientation:\">Source<\/a><\/p>\n<p>You don\u2019t need to, but because I like to have clean code, I removed these lines in my .plist files:<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&lt;key&gt;UISupportedInterfaceOrientations&lt;\/key&gt;\n&lt;array&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;UIInterfaceOrientationPortrait&lt;\/string&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;UIInterfaceOrientationLandscapeLeft&lt;\/string&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;UIInterfaceOrientationLandscapeRight&lt;\/string&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;UIInterfaceOrientationPortraitUpsideDown&lt;\/string&gt;\n&lt;\/array&gt;\n&lt;key&gt;UISupportedInterfaceOrientations~ipad&lt;\/key&gt;\n&lt;array&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;UIInterfaceOrientationPortrait&lt;\/string&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;UIInterfaceOrientationPortraitUpsideDown&lt;\/string&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;UIInterfaceOrientationLandscapeLeft&lt;\/string&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;UIInterfaceOrientationLandscapeRight&lt;\/string&gt;\n&lt;\/array&gt;<\/code><\/pre><br \/>\nYou can remove them with a text editor or using Xcode and deleting <i>Supported interface orientations<\/i> and <i>Supported interface orientations (iPad)<\/i>.<\/p>\n<p>Next up is <i>willRotateToInterfaceOrientation<\/i> and <i>willAnimateRotationToInterfaceOrientation<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I haven\u2019t updated my code for a while because I wanted to continue to support iOS5 on first generation iPads. Since Apple allows older devices to download older versions of the software, and my code in the App Store appears to be stable, I decided to update the existing code and get rid of deprecated &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=2506\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Deprecated iOS Methods: Rotation Setup<\/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-2506","post","type-post","status-publish","format-standard","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2506","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=2506"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2506\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}