3

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

Simon k
  • 403
  • 1
  • 5
  • 17
  • Have you add your google "KEY" in your code? – Yogendra Girase Dec 06 '16 at 14:22
  • No, that is just representing the key I'm using. The key is not important. In the code I'm using the real key of course. – Simon k Dec 06 '16 at 14:23
  • Enable verbose for the google maps and check again. – Sachin Vas Dec 06 '16 at 15:22
  • @New16 Can you be more specific? Im not sure i know what you mean. – Simon k Dec 06 '16 at 15:28
  • @Simonk i got confused about it. Check for XCode Device Logs to check the errors. – Sachin Vas Dec 06 '16 at 15:37
  • @New16 Okay, there is no reports on crashes from my app (not from today at least). Im still developing the app so, I'm using the simulator right now. These crashes would be shown in the console output and there is no crashes or errors regarding Google Maps. Do you know if I'm setting the API key correctly? – Simon k Dec 06 '16 at 15:46
  • Yeah, it should be fine. Override the init methods of ViewController and try once. – Sachin Vas Dec 06 '16 at 15:58
  • Okay tried that now. I set the API key in "required init?(coder aDecoder: NSCoder)" - that didn't do a difference tho :( Ill keep looking – Simon k Dec 07 '16 at 07:58
  • Seeing the same thing in my action extension. Did you ever solve this? I'm using the correct API key and verified that my View controller works from within the app. – lateAtNight May 21 '17 at 18:41
  • @lateAtNight - Never found a solution and I dont have access to the source code anymore - Sorry :( – Simon k May 22 '17 at 06:47

1 Answers1

0

A bit late to the party, but I was facing a similar problem with Google Places SDK in a Today Extension. Though the API-key was provided with success I still received an error.

The solution for me was to go to Google Cloud Platform and then editing the api-key. I had set a restriction to only accept requests from iOS apps with registered bundle identifiers. I added the missing bundle identifier for the Today Extension and saved.

Try going to Google Cloud Platform -> Google Maps -> APIs -> Maps SDK for iOS -> Credentials and edit the key used in the app. Under Application Restrictions you can add the bundle identifier for your Action Extension to the list of bundle identifiers.

billgert
  • 66
  • 6