Exception:Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey:…] prior to use

前端 未结 10 1862
挽巷
挽巷 2021-01-04 12:44

I am trying to implement Google Maps SDK into my project using Swift 2.0. I follow this but when running this, my app is getting the following error:

2015-08         


        
10条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 13:47

    You should set up API keys before you set up the UIWindow in AppDelgate, if your initial View Controller uses GoogleMaps.

    For example:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            //MARK: Google Maps setup
            GMSServices.provideAPIKey("YOUR API KEY")
            GMSPlacesClient.provideAPIKey("YOUR API KEY")
    
            let window = UIWindow(frame: UIScreen.main.bounds)
            window.backgroundColor = UIColor.white
            window.makeKeyAndVisible()
            window.rootViewController = ViewController()
            self.window = window
            return true
        }
    

提交回复
热议问题