Fix iOS 7 problem without breaking iOS 6 development?

Discussion in 'iOS Programming' started by ArtOfWarfare, Jan 10, 2014.

  1. ArtOfWarfare, Jan 10, 2014
    Last edited by a moderator: Jan 11, 2014

    ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #1
    I have two development machines:
    1 - Original MacBook Air, maxed out with OS X 10.7.5, Xcode 4.6, and iOS SDK 6.1.
    2 - Original Al iMac, running OS X 10.9.1, Xcode 5.0.2, and iOS SDK 7.0.3.

    Most of my development is done on the MacBook Air, but I'd like to ultimately release the app for iOS 7 (and maybe iOS 6 too... I don't really care about that.)

    Mostly everything is fine - when I run the simulator on my MBA, it shows up running iOS 6 fine, and when I run the simulator on my iMac, it shows up running iOS 7 fine except one issue: a search bar at the top of a modal screen overlaps the status bar.

    I'm using auto layout. How can I fix this issue without breaking my ability to develop and test on my MacBook Air?

    (And I realize that the best choice would be to get a newer portable. I don't have a steady income right now and I have a huge amount of debts, so I can't afford to do that. I'm in the process of rocking my interviews with a company that I understand pays handsomely... but I don't know how much longer until they make me an offer, if they ever actually do.)
     
  2. ArtOfWarfare, Jan 11, 2014
    Last edited: Jan 11, 2014

    ArtOfWarfare thread starter macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    After a lot of searching, I found this helpful blog post:

    http://blog.ittybittyapps.com/blog/2013/11/08/working-with-ios-6-and-7/

    His macro made me realize that that's probably the best way to maintain compatibility between Xcode 4.6 and 7.

    I also found this StackOverflow post:

    http://stackoverflow.com/a/19116595/901641

    Here's the final code I ended up using:
    Code:
    #warning Revisit when iOS 7 only
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
        if ([self respondsToSelector:@selector(topLayoutGuide)]) {
            [self.view removeConstraint:self.topSpaceConstraint];
            
            self.topSpaceConstraint = [NSLayoutConstraint constraintWithItem:self.searchBar
                                                                   attribute:NSLayoutAttributeTop
                                                                   relatedBy:NSLayoutRelationEqual
                                                                      toItem:self.topLayoutGuide
                                                                   attribute:NSLayoutAttributeBottom
                                                                  multiplier:1
                                                                    constant:0];
            [self.view addConstraint:self.topSpaceConstraint];
            [self.view setNeedsUpdateConstraints];
            [self.view layoutIfNeeded];
        }
    #endif
     

Share This Page