So i have this action extension that needs to use Google maps. Usually when you want to use Google Maps in an iOS app, you add the key in AppDelegates didFinishLaunchingWithOptions
function.
In an App Extension you don't have an AppDelegate file to do this stuff in, so where do i put it?
I've tried to put it in :
override func viewDidLoad() {
GMSServices.provideAPIKey("KEY")
GMSPlacesClient.provideAPIKey("KEY")
super.viewDidLoad()
}
I have also tried to put it after super.viewDidLoad()
, but that didn't do any difference.
When I'm sure i got a valid location i load a view in the map:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.currentCoordinate = Coordinate(longitude: locations[0].coordinate.longitude, latitude: locations[0].coordinate.latitude)
let mapCameraPosition:GMSCameraPosition = GMSCameraPosition.cameraWithLatitude(self.currentCoordinate.latitude, longitude: self.currentCoordinate.longitude, zoom: 12)
let mapFrame:CGRect = CGRect(x: 0, y: 0, width: mapView.frame.width, height: 200)
let map:GMSMapView = GMSMapView.mapWithFrame(mapFrame, camera: mapCameraPosition)
self.mapView.addSubview(map)
}
The view i get looks like this:
In the Google Console I've added the bundle identifier for both the main app AND the extension, and restricted use to these to ID's. Ive regenerated the API key and added it again.
I can validated that the GoogleService-Info.plist
has the correct API key when the app is running...
What am I doing wrong?
UPDATE
Ive validated that both the ´GMSServices.provideAPIKey("KEY")´ & ´GMSPlacesClient.provideAPIKey("KEY")´ return true. So that concludes that it wasn't an API key issue. It seems that this is a known issue according to this issue posted on code.google.com