Google Maps API for iOS的API密钥例外 [英] Exception on API Key of Google Maps API for iOS
问题描述
我正在使用Google Maps API for iOS开发iOS应用程序。我为我的项目安装了CocoaPod,并根据Google Developer上的教程进行配置。但是,当我运行我的项目时,它说
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
***由于未捕获异常'GMSServicesException',终止应用程序,原因:'Google Maps SDK for iOS必须在使用之前通过[GMSServices providesAPIKey:...]初始化。
*** Terminating app due to uncaught exception 'GMSServicesException', reason: 'Google Maps SDK for iOS must > be initialized via [GMSServices provideAPIKey:...] prior to use'
但我已经打电话给GMSServices。
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
}
....
(* *************)是我的API密钥。
(**************) is my API Key.
由于Google Maps API使用Objective C,所以我创建了一个桥接头导入库。
And because Google Maps API use Objective C, so I created a Bridging Header to import the library.
我尝试在[application:didFinishLaunchingWithOption]上设置断点,但它会在运行该函数之前引发异常,我认为是非常奇怪的。
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.
推荐答案
问题终于解决了,原因是我在一个模型类中使用Google Maps库初始化一个字段它会在应用程序运行之前创建。所以这个错误发生。当我将这个变量移入方法时,问题就解决了。以下是导致错误的代码:
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
After
class PlaceManager {
func getSuggestions(queryString:String) -> [String]{
let placeClient = GMSPlacesClient()
...
}
}
这篇关于Google Maps API for iOS的API密钥例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!