Search code examples
iphoneios6google-maps-sdk-ios

How to add google map to ios6 sdk


When i try to add Google map to ios6 according to this Link Google MAP

and i get the API KEY and put it in my app but it crashed and the reason "Google MAP SDK for ios must be Initialized via [GMSServices ProvideAPIKey:...]"

Can any body help me, give me video how to do it any thing ...

    #import "AppDelegate.h"
#import <GoogleMaps/GoogleMaps.h>
#import "ViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
[GMSServices provideAPIKey:@"AIzaSyBoOGGGQnvDydbKcxGeB1of6wu2ibE6Rjk"];

}

Solution

  • Did you do step 8 here?

    If you did, can you update your question with the code for your application:didFinishLaunchingWithOptions: method?

    UPDATE:

    Move the call to [GMSServices provideAPIKey:] higher up in the application:didFinishLaunchingWithOptions: method, somewhere before this line:

    self.window.rootViewController = self.viewController;
    

    This line sets the root view controller, which will cause the view controller's root view to be allocated, by calling loadView. In Google's sample code loadView is what creates the GMSMapView, and so with the code as you have it now, you are trying to create a GMSMapView before providing the API key, which causes the Google Maps SDK for iOS to crash.

    Also by the way, you had placed your call to [GMSServices provideAPIKey:] after the return statement, so it would never get called.