10

I'm trying to make my iOS7 app work on iOS8 and I saw that the UISearchController replaces the UISearchDisplayController in iOS8.

Of course I can use UISearchController instead of UISearchDisplayController, but than my app is no longer working on iOS7.

How can I make my app work on both iOS versions? Do I need to make another storyboard for iOS8?

Thanks in advance

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Maurice
  • 278
  • 3
  • 10

2 Answers2

13

If your Deployment Target is set to iOS 7 and you wish to support iOS 8, you can still use UISearchDisplayController and it should run without issue on iOS 8, and without warnings presented in Xcode. I have not experienced any misbehavior with my apps that implement UISearchDisplayController. When I decide to no longer support iOS 7, then I will replace it completely with UISearchController.

You may be able to detect the OS version and implement UISearchController programmatically if 8+, but if you're using a Storyboard it would be difficult to implement both unless you create two different Storyboards, one for each OS. But I don't really find that necessary when you need to support the previous OS. Deprecation normally does not mean it will not work anymore when running on the latest OS, but rather it's just not recommended to use anymore because there are better solutions available. It's rare when deprecated methods do not work properly when run on newer iOS versions.

Jordan H
  • 52,571
  • 37
  • 201
  • 351
  • Thank you! Btw, is there a better way instead of using Storyboards? – Maurice Aug 12 '14 at 06:47
  • Not really, it's more of a personal preference. Storyboard/nibs or pure code, it's up to you. :) – Jordan H Aug 12 '14 at 15:32
  • Deprecation doesn't mean it will not work anymore when running on the latest OS - Very true. Unless Apple decides to totally remove it (generally it's due to non-technical reason, such as the "real" UUID), old classes are not likely to be removed even after a lot of version updates. Considering the lifespan of an app, normally you don't need to start using the newest class right away. – superarts.org Apr 29 '15 at 07:40
0
// Above ios 8.0
float os_version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (os_version >= 8.000000)
{
      //Use UISearchController  
        // self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
}
else
{
     //use UISearchDisaplyController
     // self.controller = [[UISearchDisplayController alloc]initWithSearchBar:self.searchBar contentsController:self];

}
Sabareesh
  • 3,585
  • 2
  • 24
  • 42
  • 1
    So I have to remove the UISearchDisplayController from my Storyboard? And I have to implement all delegate-methods from both UISearchController and UISearchDisplayController in the same class? (self) – Maurice Aug 11 '14 at 14:35
  • I don't think that's a good idea, IMO. Protocols have a different signature, and you'd have to declare they conform to both, while only fulfilling one at a time. – Alex Oct 24 '14 at 05:32
  • Technically it's the way to solve this sort of problem, but for a whole UI class it's too much work. – superarts.org Apr 29 '15 at 07:41
  • With modern @available checking, [this answer](https://stackoverflow.com/a/65190018/3167040) would be how to implement this sort of thing today. Only commenting in case someone else happens to run into the same issue I did. – ReinstateMonica3167040 Dec 07 '20 at 22:12