更新到版本3.0.2后,地方自动完成功能不起作用-Google iOS SDK

Ale*_*lex 5 ios google-places-api swift google-places-autocomplete

GMSAutocompleteResultsViewController到目前为止,我已经实现了使用场所自动完成功能的工作正常。但是,当我将SDK更新为3.0.2时,它停止工作了。如果我恢复到版本2.7.0,则开始工作。

我已经通过了迁移指南,但没有得到我所缺少的东西。我检查了示例,没有发现任何变化。有人会指出我正确的方向来使其再次起作用吗?

class PlaceAutoCompleteController: BaseViewController {

    //MARK: - Property declaration
    private var resultsViewController = GMSAutocompleteResultsViewController()
    private lazy var searchController = UISearchController(searchResultsController: resultsViewController)
    private var viewModel: PlaceTypeAheadViewModel
    var storeSelectionDelegate: StoreSelectionDelegate?

    //MARK: - Life cycle
    init(withViewModel aviewModel: PlaceTypeAheadViewModel) {
        viewModel = aviewModel
        super.init()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        setupProperties()
    }
}

//MARK: - Property setup
extension PlaceAutoCompleteController {

    /// Setting up view default properties
    func setupProperties() {

        resultsViewController.view.backgroundColor = UIColor.white
        resultsViewController.tableCellBackgroundColor = .white
        resultsViewController.delegate = self

        // Specify the place data types to return.
//        let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue) |
//            UInt(GMSPlaceField.placeID.rawValue))!
//        resultsViewController.placeFields = fields

        let filter      = GMSAutocompleteFilter()

        //suitable filter type
        filter.type     = .establishment
        filter.country  = viewModel.getCountryId()
        resultsViewController.autocompleteFilter = filter

        searchController.searchResultsUpdater = resultsViewController

        // Put the search bar in the navigation bar.
        searchController.searchBar.sizeToFit()
        searchController.searchBar.placeholder = "Search places"
        let searchBgView = UIView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 44))
        searchBgView.addSubview(searchController.searchBar)
        view.addSubview(searchBgView)

        // Prevent the navigation bar from being hidden when searching.
        searchController.hidesNavigationBarDuringPresentation = false

        // This makes the view area include the nav bar even though it is opaque.
        // Adjust the view placement down.
        extendedLayoutIncludesOpaqueBars = false
        edgesForExtendedLayout = []

    }
}

// Handle the user's selection.
extension PlaceAutoCompleteController: GMSAutocompleteResultsViewControllerDelegate {

    func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
                           didAutocompleteWith place: GMSPlace) {
        searchController.isActive = false
        AppManager.setPlace(withPlaceId: place.placeID ?? "" , name: place.name ?? "" , latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
        openStoreSelection()
    }

    func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
                           didFailAutocompleteWithError error: Error){
        // TODO: handle the error.
        print("Error: ", error.localizedDescription)
    }

    // Turn the network activity indicator on and off again.
    func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
        UIApplication.shared.isNetworkActivityIndicatorVisible = true
    }

    func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
        UIApplication.shared.isNetworkActivityIndicatorVisible = false
    }

    /// Open store selection screen with selected country
    func openStoreSelection() {
        navigateToStoreSelection()
    }
}



Run Code Online (Sandbox Code Playgroud)

提前致谢。

Ale*_*lex 0

获得了商务人士的访问权限,接受了隐私政策,但我在他们之前共享的凭据中找不到应用程序密钥。现在我开始使用 iOS 密钥(由 Google 服务自动创建),它与更新的 sdk 版本(即 3.0.3)完美配合

在此输入图像描述