Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception on API Key of Google Maps API for iOS

I am developing an iOS app using Google Maps API for IOS. And I installed the CocoaPod for my project and configure them according to tutorial on Google Developer. However, when I run my project, it says

*** Terminating app due to uncaught exception 'GMSServicesException', reason: 'Google Maps SDK for iOS must > be initialized via [GMSServices provideAPIKey:...] prior to use'

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

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

(**************) is my API Key.

And because Google Maps API use Objective C, so I created a Bridging Header to import the library.

I tried to set breakpoint on [application:didFinishLaunchingWithOption]. But it will raise exception before run that function, which I think is very weird.

So confused about it. Thanks in advance.

like image 266
Jerry Zhao Avatar asked Sep 27 '15 20:09

Jerry Zhao


1 Answers

Problem finally solved, the reason is that I initialize a fields using Google Maps library in the one model class and it will be created before the app run. So this error happens. When I moved this variable into the method, problem solved. Following is the code that causes error:

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

After

class PlaceManager {
    func getSuggestions(queryString:String) -> [String]{
        let placeClient = GMSPlacesClient()
        ...
    }
}
like image 200
Jerry Zhao Avatar answered Sep 26 '22 01:09

Jerry Zhao