Unable to access Google Map in Swift AppDelegate file

I am learning Swift and struggling to figure out how to integrate the framework of the Google Map SDK. I created a new project in Xcode 6, imported the frameworks required by the Google Map SDK for iOS.

However, when I import the Google Maps structure using (import) into the AppDelegate.swift file, the environment is not recognized.

Unable to find a solution anywhere. Please, help.

+7
ios swift xcode6 google-maps google-maps-sdk-ios
source share
3 answers

After you imported the Google Maps iOS SDK, you need to define the title of the bridge, then the SDK will be recognized.

To create this bridge header, add a custom Objective-C file to the project (for example: a .m ). Xcode will ask you if you need to configure the bridge header.

Click Yes to continue.

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

Just add #import <GoogleMaps/GoogleMaps.h> to the bridge title and you're good to go!

In addition, you can now delete this temporary Objective-C file.

+11
source share

Now you can install the SDK through CocoaPods, and you will not need to add a bridge header. Check out this tutorial ( Google Maps iOS SDK Link ) and just add the following code to your AppDelegate didFinichLaunchingWithOptions function.

 GMSServices.provideAPIKey("API_KEY") 
+1
source share

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

Select Yes to customize the Objective-C bridge title.

Delete the temporary Objective-C file you just created.

In the projectName-Bridging-Header.h file you 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 a complete sample.

0
source share

All Articles