Reputation: 15
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"];
}
Upvotes: 1
Views: 5728
Reputation: 625
I moved this line :
[GMSServices provideAPIKey:@"myAPIKey"];
in the method viewDidLoad and now it works.
Upvotes: 0
Reputation: 11217
Start your delegate like this instead of yours :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[GMSServices provideAPIKey:@"AIzaSyB2LJ2ppIVtkNh0lkG9J1tXW2RcHtI0FKY"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//////
}
Upvotes: 0
Reputation: 13035
If you moved it and still get an error, here is what I did :
Copy the file GoogleMaps.bundle file into your framework folder in Xcode
"GoogleMaps.framework/Versions/A/Resources/GoogleMaps.bundle"
..and make sure it's in your Targets (not Project) Build Phases settings under "Copy Bundle Resources"
Upvotes: 0
Reputation: 17624
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.
Upvotes: 8
Reputation: 310
Move your GMSServices provideAPIKey to the top of the didFinishLaunchingWithOptions, that will fix your issue as right now you're returning before providing the API Key.
Upvotes: 0