Swift 3 iOS -Google GMSAutoComplete 自升级后出现故障

Swift 3 iOS -Google GMSAutoComplete malfunctioning since upgrade

错误说明:

我正在使用 Google GMSAutocompleteViewController

我在 AppDelegate 中有我的 API 密钥,Swift 3 Xcode 8 的最新 pod,导入 GoogleMaps 和导入 Google PlacesAPI 在 vc 的顶部和 appDelegate 中,我的互联网连接很好。

当我使用 Swift 2.2 时,每当我输入地址时,一切正常。现在我升级到 Swift 3 时不时地在地址上出错,然后出现 "Can't load search results" 云标题。当我关闭 vc 并重试时,我一直得到相同的标题。我尝试关闭应用程序并重新启动模拟器,但它不允许我访问自动完成服务。我远远低于 2500 次免费每日搜索限制,因为实际上只有我在测试该应用程序。

我还注意到 Google AutoComplete 文档说要使用 GMSPlacesClient.provideAPIKey("...") 但是 GMSPlacesClient 方法提供的APIKey 不可用所以我只能使用 GMSServices.provideAPIKey("..")。我想知道这是问题的一部分。

有人知道这个问题的解决方法吗?

AppDelegate:

import UIKit
import GoogleMaps
import GooglePlacesAPI
import SystemConfiguration

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    override init() {
        super.init()

        //Google Maps API Key
        GMSServices.provideAPIKey("WORKS")

        GMSPlacesClient.provideAPIKey("DOES NOT WORK")
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

我的代码来自 googlePlaces:

import UIKit
import GooglePlaces
import GoogleMaps

class ViewController: UIViewController {


  @IBAction func onLaunchClicked(sender: UIButton) {
    let acController = GMSAutocompleteViewController()
    acController.delegate = self
    present(acController, animated: true, completion: nil)
  }
}

extension ViewController: GMSAutocompleteViewControllerDelegate {

  func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
    print("Place name: \(place.name)")
    print("Place address: \(place.formattedAddress)")
    print("Place attributions: \(place.attributions)")
    dismiss(animated: true, completion: nil)
  }

  func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
    print(".....\(error)")
    dismiss(animated: true, completion: nil)
  }

  func wasCancelled(_ viewController: GMSAutocompleteViewController) {
    dismiss(animated: true, completion: nil)
  }
}

您应该将 GooglePlacesGooglePlacePickerGoogleMaps 放入您的 Podfile:

pod 'GooglePlaces'
pod 'GooglePlacePicker'
pod 'GoogleMaps'

并提供您的 API_KEY:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    GMSPlacesClient.provideAPIKey("API_KEY_HERE")

    return true
}

有关详细信息,请遵循本指南:https://developers.google.com/places/ios-api/start