{"id":87,"date":"2014-01-21T11:28:02","date_gmt":"2014-01-21T15:28:02","guid":{"rendered":"http:\/\/blog.blackgecko.com\/?p=87"},"modified":"2014-01-21T11:48:36","modified_gmt":"2014-01-21T15:48:36","slug":"transitioning-to-ios7","status":"publish","type":"post","link":"http:\/\/blog.blackgecko.com\/?p=87","title":{"rendered":"Transitioning to iOS7"},"content":{"rendered":"<p>A lot of people are taking the plunge, like it or not, into iOS7 &#8220;optimized&#8221; apps. Some folks were going to take their time and transition slowly but Apples recent announcement to developers that February was it and that like it or not they HAD to build iOS7 apps by February has pushed timelines into hyperdrive.<\/p>\n<p>Here are a few useful things I&#8217;ve learned along the way that might may others transition to iOS7 a little easier:<\/p>\n<p><strong>1. iOS7 or not<\/strong><br \/>\nThis little bit of code<\/p>\n<pre class=\"brush: objc; title: ; notranslate\" title=\"\">\r\nif (floor(NSFoundationVersionNumber) &lt;= NSFoundationVersionNumber_iOS_6_1)\r\n<\/pre>\n<p>can easily detect if you&#8217;re running on iOS6.1 or older. Of course the opposite is also true. You can use this code<\/p>\n<pre class=\"brush: objc; title: ; notranslate\" title=\"\">\r\nif (floor(NSFoundationVersionNumber) &gt; NSFoundationVersionNumber_iOS_6_1)\r\n<\/pre>\n<p>can detect if you&#8217;re running on iOS7 or newer. Very helpful if you want to keep your old code in place, to look nice for your customers running iOS6.1 or older.<\/p>\n<p>In case you <strong>have<\/strong> to continue supporting iOS6 \/ Xcode 4 then creating the following header file<\/p>\n<pre class=\"brush: objc; title: ; notranslate\" title=\"\">\r\n#ifndef PK_Xcode4_support_h\r\n#define PK_Xcode4_support_h\r\n\r\n#ifndef NSFoundationVersionNumber_iOS_6_0\r\n    #define NSFoundationVersionNumber_iOS_6_0  993.00\r\n#endif\r\n\r\n#ifndef NSFoundationVersionNumber_iOS_6_1\r\n    #define NSFoundationVersionNumber_iOS_6_1  993.00\r\n#endif\r\n\r\n#endif\r\n<\/pre>\n<p>will ensure that your code behaves properly when compiled with Xcode 4 or Xcode 5. By the way a quick look in <code>NSObjCRuntime.h<\/code> will confirm that both <code> NSFoundationVersionNumber_iOS_6_0<\/code> and <code> NSFoundationVersionNumber_iOS_6_1<\/code> are supposed to be defined as <code>993.00<\/code>. <\/p>\n<p><strong>2. Mind the gap<\/strong><br \/>\nOne of the new <em>features<\/em> of iOS7 is that your views can slide under the navigation bar. If you want to do this on purpose then more power to you but if you&#8217;re just trying to get your app to look reasonable then this little bit of code<\/p>\n<pre class=\"brush: objc; title: ; notranslate\" title=\"\">\r\nif (floor(NSFoundationVersionNumber) &gt; NSFoundationVersionNumber_iOS_6_1) {\r\n    \/\/ Setting traslucent make sure that the view doesn't slide under in iOS7\r\n    self.navigationController.navigationBar.translucent = NO;\r\n}\r\n<\/pre>\n<p><strong>3. Wrapping table cells<\/strong><br \/>\nSome code relies on the fact that the superview of a <code>UITableViewCell<\/code> to be a <code>UITableView<\/code>. This is no long true under iOS7. As of iOS7 <code>UITableViewCell<\/code> superview is actually <code>UITableViewCellScrollView<\/code> (which is so to support sliding table cells for delete etc). In general it&#8217;s probably a bad idea to depend on the view hierarchy (Apple can and does change it) but if you&#8217;re going to this little bit of code<\/p>\n<pre class=\"brush: objc; title: ; notranslate\" title=\"\">\r\nid cellSuperview = [cell superview];\r\nif (floor(NSFoundationVersionNumber) &gt; NSFoundationVersionNumber_iOS_6_1) {\r\n     cellSuperview = [cellSuperview superview];\r\n}\r\n<\/pre>\n<p>will do the trick. <code>cellSuperview<\/code> should, at the end of this code, point to the <code>UITableView<\/code> that the cell lives in.<\/p>\n<p><strong>4. Popovers<\/strong><br \/>\nOne problem that became apparent very quickly, as I was transitioning code to iOS7, is that <code>UIPopoverController<\/code>&#8216;s we&#8217;re a very happy bunch. All of the popovers looked wrong. After much digging and searching I discovered that iOS7 <code>UIPopoverController<\/code>s looked at the contents <em>preferred<\/em> content size. To that end I wrote this method<\/p>\n<pre class=\"brush: objc; title: ; notranslate\" title=\"\">\r\n- (void)setContentSize:(CGSize)contentSize animated:(BOOL)animated{\r\n    if (floor(NSFoundationVersionNumber) &gt; NSFoundationVersionNumber_iOS_6_1) {\r\n        CGSize size = contentSize;\r\n        if (size.width == 0){\r\n            size.width = 320;\r\n        }\r\n        if ((size.height == 0) || (size.height == 44)){\r\n            size.height = 1100;\r\n        }\r\n        [self.contentViewController setValue:[NSValue valueWithCGSize:size] forKey:@&quot;preferredContentSize&quot;];\r\n    } else {\r\n        [self setPopoverContentSize:contentSize animated:animated];\r\n    }\r\n}\r\n<\/pre>\n<p>in a category class for <code>UIPopoverController<\/code>. This code checks if we&#8217;re running under iOS7 or 6. If we&#8217;re running under iOS7 it looks at the size being passed in. The code assumes that the argument <code>contentSize<\/code> is from a call to the contents <code>UIViewController<\/code> method <code>contentSizeForViewInPopover<\/code>. Under iOS7 this method has been deprecated and returns <code>width=0<\/code> and <code>height=0<\/code>. Previously this method would have returned <code>width=320<\/code> and <code>height=1100<\/code>. This category method then sets the size back to the original default and then sets the <code>preferredContentSize<\/code> of the <code>contentViewController<\/code> so that the <code>UIPopoverController<\/code> will once again be happy.<\/p>\n<p><strong>5. Searching Popovers<\/strong><br \/>\nOne problem I came across, which is less of an iOS6 to iOS7 problem and more of an iOS7 to iOS7.1 problem, is searching in popovers. There seems to be a problem with the search view not properly managing the search view. The result is that as you type and get results for the search the view overwrites the underlying view BUT the underlying view remains active. This is a serious mess. So far I haven&#8217;t found a good answer other then using iOS7.1. Apparently this is a good solid iOS7 SDK bug that Apple has fixed. As of yet I haven&#8217;t found a good backwards fix.<\/p>\n<p>Well, that&#8217;s all for now. As I discover more of the tips I&#8217;ll post the.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A lot of people are taking the plunge, like it or not, into iOS7 &#8220;optimized&#8221; apps. Some folks were going to take their time and transition slowly but Apples recent announcement to developers that February was it and that like &hellip; <a href=\"http:\/\/blog.blackgecko.com\/?p=87\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,11,6,8,1],"tags":[],"class_list":["post-87","post","type-post","status-publish","format-standard","hentry","category-cocoa","category-ios","category-objective-c","category-programming","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/blog.blackgecko.com\/index.php?rest_route=\/wp\/v2\/posts\/87","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.blackgecko.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.blackgecko.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.blackgecko.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.blackgecko.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=87"}],"version-history":[{"count":10,"href":"http:\/\/blog.blackgecko.com\/index.php?rest_route=\/wp\/v2\/posts\/87\/revisions"}],"predecessor-version":[{"id":97,"href":"http:\/\/blog.blackgecko.com\/index.php?rest_route=\/wp\/v2\/posts\/87\/revisions\/97"}],"wp:attachment":[{"href":"http:\/\/blog.blackgecko.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.blackgecko.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.blackgecko.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}