8

I'm studying Swift and am struggling to figure out how to integrate the Google Map SDK frameworks. I created a new project in Xcode 6, imported the frameworks required as per Google Map SDK instructions for iOS.

However when I import the Google Maps framework using (import )to the AppDelegate.swift file the framework isn't recognised.

Can't find a solution anywhere. Please help.

friedbunny
  • 2,421
  • 1
  • 23
  • 38
Cathal
  • 153
  • 1
  • 8

3 Answers3

11

After you imported Google Maps iOS SDK, you need to have a bridge header defined, then the SDK will be recognized.

To create this bridge header, add an arbitrary Objective-C file(eg: a .m file) to your project. Xcode will prompt to ask you if to configure a bridge header for you.

Click Yes to continue.

A file ending with -Bridging-Header.h will be added to your project.

Simply add #import <GoogleMaps/GoogleMaps.h> in the bridge header, and you are good to go!

Also, it's safe to delete that temporary Objective-C file now.

Aaron He
  • 5,509
  • 3
  • 34
  • 44
  • Thank you so much Aaron, that solved my problem. It seems like a bit of a hack creating a .m file purely to get the Bridging Header option, maybe it will be easier in the release version. – Cathal Jun 24 '14 at 12:01
  • @CathalYea, I agree. I expected the bridge header will be added when an Objecitve-C library is imported to the project. Hope this will be improved in the next seed. – Aaron He Jun 24 '14 at 14:55
  • hi, can you show me how to add the API key into swift please? Thanks. From the google maps sdk: https://developers.google.com/maps/documentation/ios/start#getting_the_google_maps_sdk_for_ios Add the following to your application:didFinishLaunchingWithOptions: method, replacing API_KEY with your API key. [GMSServices provideAPIKey:@"API_KEY"]; – Duc Jul 07 '14 at 23:10
  • 1
    @Duc just call `GMSServices.provideAPIKey` with your API key in `func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?)` – Aaron He Jul 08 '14 at 03:27
  • Now with Xcode Beta 3 - this no longer seems to work! :( – Cathal Jul 10 '14 at 17:08
1

You can now install SDK via CocoaPods, and you wont need to add the Bridging Header. View this tutorial(Google Maps iOS SDK Link) and just add the following code to your AppDelegate's didFinichLaunchingWithOptions function.

GMSServices.provideAPIKey("API_KEY")
danielsalare
  • 335
  • 3
  • 14
0

Add a temporary Objective-C file to your project. You may give it any name you like.

Select Yes to configure an Objective-C bridging header.

Delete the temporary Objective-C file you just created.

In the projectName-Bridging-Header.h file just created, add this line:

'#import < GoogleMaps/GoogleMaps.h >'

Edit the AppDelegate.swift file:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    GMSServices.provideAPIKey("AIza....") //iOS API key

    return true
}

Follow the link for full sample

Atul Kaushik
  • 5,181
  • 3
  • 29
  • 36