Cathal
Cathal

Reputation: 163

Cannot access Google Map Framework in Swift AppDelegate file

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.

Upvotes: 8

Views: 6292

Answers (3)

Atul Kaushik
Atul Kaushik

Reputation: 5201

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

Upvotes: 0

danielsalare
danielsalare

Reputation: 335

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")

Upvotes: 1

Aaron He
Aaron He

Reputation: 5549

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.

Upvotes: 11

Related Questions