-2

I am creating a application in swift for both iOS7 & iOS8 compatible. My app runs in iOS8 (as deployment target) easily for both simulator and device. But it's not running in iOS7 as deployment target under "Info" tab. For iOS7, if I choose iPhone 5s(8.1) simulator then it works, but if choose any simulator of 7.0/7.1 sdk/iPhone device, then my app crashes. What should I do? My base SDK on "build settings" tab in xcode is iOS 8.1. Below is my code. My app crashes on "UISearchController(searchResultsController: nil)" of below code. Any suggestion must be appreciable.

 override func viewDidLoad() {
        super.viewDidLoad()

        // Search Controller Setup
        searchController = UISearchController(searchResultsController: nil)
        searchController.searchBar.delegate = self
        searchController.searchResultsUpdater = self
        searchController.dimsBackgroundDuringPresentation = false
        searchController.searchBar.placeholder = "ব্র্যান্ড/সংস্থা/দোকান খুঁজুন"

        // Make sure the that the search bar is visible within the navigation bar.
        searchController.searchBar.sizeToFit()
        tableView.tableHeaderView = searchController.searchBar
        definesPresentationContext = true
    }
llanato
  • 2,508
  • 6
  • 37
  • 59
Nuibb
  • 1,800
  • 2
  • 22
  • 36
  • https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UISearchController/index.html, I recommend to read the _availability_ section. educational. – holex Jan 26 '15 at 13:46

1 Answers1

3

UISearchController is available from IOS8, if you want to use something like that in IOS7, you should use the UISearchDisplayController (which is deprecated in IOS8).

Dániel Nagy
  • 11,815
  • 9
  • 50
  • 58
  • Thank you. But it's not the only issue what i'm facing now. If i comment out all the search controller code from viewDidLoad(), i can't run my app yet on iPhone 5s(7.1) simulator or iPhone device under 7.1 sdk. What should i do ? – Nuibb Jan 26 '15 at 12:19
  • Why you can't run it now? What is the error message, and where it came from? – Dániel Nagy Jan 26 '15 at 12:21
  • My base sdk is iOS 8.1, but if choose deployment target iOS 7.1 and set the active scheme to iPhone 5s (7.1)/device connected with my mac, then my app not running on either simulator or device and shows an alert message with "iPhone 5s is not available. Please select a different device and try again" – Nuibb Jan 26 '15 at 12:34
  • @Nuibb If you click on Product > Destination > More simulators, on the downloads tab, check the components, and probably you missing the IOS 7.1 simulator. – Dániel Nagy Jan 26 '15 at 12:56
  • Hi Daniel Nagy, Can you please see the screenshots of [this](https://www.dropbox.com/sh/anst8j58bck67ic/AABPEdyK-vTj7kijJpNh3pKsa?dl=0) link sequentially ? If i select iPhone 5s (7.1) [see 1.png file], i get messages of 3.png and 4.png file. – Nuibb Jan 26 '15 at 13:29
  • I see, but did you downloaded the simulator the way I described above? – Dániel Nagy Jan 26 '15 at 13:38
  • Hi Daniel Nagy, you are right. iOS 7.1 simulator is not installed in my xcode componets. Thanks a lot. – Nuibb Jan 27 '15 at 04:04
  • Hi Daniel, i'm targeting my app should run on both iOS 7 & iOS 8. If i use UISearchDisplayController then it runs in iOS 7. But how can i configure it for iOS 8 also ? – Nuibb Jan 27 '15 at 08:53
  • I'm not sure about the best practice, but you should check whether UISearchController is available with for example this kind of approach: http://stackoverflow.com/questions/24591952/how-do-i-do-weak-linking-in-swift/24956190#24956190 and if it's available, it's IOS8 otherwise IOS7, and instantiate either one accordingly. – Dániel Nagy Jan 27 '15 at 09:02