Google Maps API API Exception for iOS

I am developing an iOS application using the Google Maps API for IOS. And I installed CocoaPod for my project and configured them according to the tutorial in Google Developer. However, when I launch my project, he says

*** Application termination due to the uncaught exception "GMSServicesException", reason: "The Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey: ...] before use"

But I already call "GMSServices.provideAPIKey" on AppDelegate.swift. Below is the code:

....
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    GMSServices.provideAPIKey("***********************")
    return true
}
....

(**************) is my API key.

And since the Google Maps API uses Objective-C, so I created a Bridging header to import the library.

[application: didFinishLaunchingWithOption]. , , , , .

. .

+4
3

, , , Google Maps , . . , . , :

class PlaceManager {
    let placeClient = GMSPlacesClient()
    ...
    func getSuggestions(queryString:String) -> [String]{
        ...
    }
}

class PlaceManager {
    func getSuggestions(queryString:String) -> [String]{
        let placeClient = GMSPlacesClient()
        ...
    }
}
+5

didFinishLaunchingWithOptions willFinishLaunchingWithOptions. , , . ( , API Google)

func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
GMSServices.provideAPIKey("***********************")

    return true
}
+2

. GMSMapView, , api. viewDidLoad .

:

class ViewController: ..... {

let mapView = GMSMapView()

:

class ViewController: ..... {

var mapView : GMSMapView?

override viewDidLoad(){
    mapView = GMSMapView()
+2

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


All Articles