How to set search as global focus for Siri on the search page?

Description

In my tvOS application, I have a search page on top of a Search Barand below Table Viewwith a possible list of results.

While we are focusing searchBarand the user clicks the voice for Siri, the results are inserted into the search bar (as expected). However, when the user scrolls the results and cannot find what he is looking for, they need to scroll up (completely back) to searchBarto use Siri again.

If the user tries to use Siri, but is searchBarNOT in focus, the global Siri starts looking for results in different applications (this is not what I want)

Question:

How to set searchBar as global focus for Siri on search page?

What I tried:

Honestly, I have no idea how to do this.

In AppDelegate.swift, a function is called to create a search controller and add it to the controller of the tab bar.

I thought about trying preferredFocusView, but after reading the documentation, I doubt that you are going to work.

func configueSearchController() -> UIViewController {

        let storyboard = UIStoryboard(name: "Search", bundle: nil)
        guard let searchResultsController = storyboard.instantiateViewController(withIdentifier: SearchViewController.storyboardIdentifier) as? SearchViewController else {
            fatalError("Unable to instatiate a SearchResultViewController from the storyboard.")
        }

        /*
         Create a UISearchController, passing the `searchResultsController` to
         use to display search results.
         */

        let searchController = UISearchController(searchResultsController: searchResultsController)
        searchController.searchResultsUpdater = searchResultsController
        searchController.searchBar.placeholder = NSLocalizedString("Enter keyword (e.g. Gastric Bypass)", comment: "")
        searchController.view.backgroundColor = Constants.Color.backgroundcolor
        searchController.searchBar.keyboardAppearance = UIKeyboardAppearance.dark
        searchController.searchBar.tintColor = Constants.Color.backgroundcolor
        searchController.searchBar.backgroundColor = Constants.Color.backgroundSearchBarColor
        searchController.searchBar.setTextColor(color: .white)
        searchController.hidesNavigationBarDuringPresentation = false
        searchController.obscuresBackgroundDuringPresentation = true
        searchController.searchBar.searchBarStyle = .minimal
        searchController.searchBar.sizeToFit()
        searchController.searchBar.focus


        //TODO: Check if this works
        searchController.searchBar.accessibilityLanguage = "en"

        //searchResultsController.tableView.tableHeaderView = searchController.searchBar

        // Contain the `UISearchController` in a `UISearchContainerViewController`.
        let searchContainer: UISearchContainerViewController = UISearchContainerViewController(searchController: searchController)

        // Finally contain the `UISearchContainerViewController` in a `UINavigationController`.
        let searchNavigationController = UINavigationController(rootViewController: searchContainer)
        searchNavigationController.navigationBar.isTranslucent = true
        searchNavigationController.navigationBar.tintColor = Constants.Color.backgroundcolor
        searchNavigationController.tabBarItem.title = "Search"
        return searchNavigationController

}
+6
source share
1 answer

Please read http://nerds.airbnb.com/tvos-focus-engine/ to make the controls customizable.

0
source

Source: https://habr.com/ru/post/1014598/


All Articles