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

前端 未结 10 1861
挽巷
挽巷 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:42

    in my case --didFinishLaunchingWithOptions-- method didn't call because i updated swift version. first make sure this method called normally. and in my case i didn't need to GMSPlacesClient.provideAPIKey("Your key"). however you can initial GMSServices in your initial viewcontroller (if its not contain map or related objet to it)

    0 讨论(0)
  • 2021-01-04 13:43

    You need to set this both in didFinishLaunchingWithOptions

    GMSPlacesClient.provideAPIKey("Your key")
    GMSServices.provideAPIKey("Your key")
    
    0 讨论(0)
  • In my app i provided key to GMSPlacesClient in AppDelegate -didFinishLaunchingWithOptions

    Ex:
    @import GooglePlaces;
    @import GoogleMaps; 
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [GMSServices provideAPIKey:@"You key"];
        [GMSPlacesClient provideAPIKey:@"Your key"];
    }
    

    For Swift:

    import GoogleMaps
    import GooglePlaces
    
    //in application(_:didFinishLaunchingWithOptions:)
    
    GMSServices.provideAPIKey("YOUR_API_KEY")
    GMSPlacesClient.provideAPIKey("YOUR_API_KEY")
    
    0 讨论(0)
  • 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
        }
    
    0 讨论(0)
提交回复
热议问题