How to add google map to ios6 sdk - iphone

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"];
}

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.

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.

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"

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]];
//////
}

I moved this line :
[GMSServices provideAPIKey:#"myAPIKey"];
in the method viewDidLoad and now it works.

Related

"Application windows are expected to have a root view controller" conditional appearance

I'm writing an app for iPhone using Xcode 4.5 and iOS6. I'm also creating a new UIWindow to be able to manage the area of the status bar (to display messages there, etc.)
I'm using storyboards and my appDelegate method looks like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
The message does not appear in the console when I put it in the method called viewDidAppear:
- (void)viewDidAppear:(BOOL)animated {
if (!window) {
window = [[SGStatusBar alloc] initWithFrame:CGRectZero];
window.frame = [[UIApplication sharedApplication] statusBarFrame];
window.alpha = 0.5f;
[self.view.window makeKeyAndVisible]; // has to be main window of app
window.hidden = NO;
}
}
The same method, put in the viewDidLoad gives a warning in the console:
2012-12-27 11:34:20.838 NewApp[433:c07] Application windows are expected to have a root view controller at the end of application launch
Is this because I've created a new UIWindow? Why the difference between those two methods is so big?
And, most importantly, how can I get rid of this warning while putting the code in the viewDidLoad method?
EDIT:
I have encountered the same problem here, but it's not the way I'd like to solve it (it's actually the way I'm solving it right now)
I've tried setting my current ViewController as my window's root view controller by doing this:
ViewController *vcB = [[UIViewController alloc] init];
window.rootViewController = vcB;
But I keep getting a warning that says:
Incompatible pointer types initializing 'ViewController *__strong' with an expression of type 'UIViewController *'
Set window.rootViewController property .
Add the following code to your delegate.h and delegate.m files.
AppDelegate.h
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) YourViewController *viewController;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[YourViewcontroller alloc] initWithNibName:#"YourViewcontroller" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Hope it works.

need help understanding my error on my first iPhone app [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
applications expected to have a root view controller console
I'm trying to build the first app by following a book step by step but I guess I'm making a mistake.
it's a simple view app with just a logo nd a label and then I click build and run and it says "build succeded", but when ios simulator pop up the app is still blank, even if I go back home and ropen the app nothing change.
I see on the debug window this statement:
2012-10-26 04:07:03.376 welcome[1219:c07] Application windows are expected to have a root view controller at the end of application launch
AS far as I understand my app lacks of a root view controller but how can I implement it?
You specify the root view controller in your appDelegate class. It should look something like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:#"theNameOfMyXib" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
The important lines that you need to add are:
self.viewController = [[[ViewController alloc] initWithNibName:#"theNameOfMyXib" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
And under initWithNibName you put the name of the xib you created your interface in.
Note: Only add autorelease if your project isn't using ARC.

White screen for ios Project

I just tried to duplicate an existing iOS project. After copying over all the files, and fixing all the errors, I am simply getting a white screen when the app launches. Any ideas? I do not have any MainWindow.xib files, nor are any xib files mentioned in my plist. Here is my launch code below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MainMenuViewController *mainMenu = [[MainMenuViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainMenu];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
When i set a breakpoint in MainMenuViewController's viewDidLoad method, it hits it just fine. Any ideas?
I just figured it out... all of my .xib files were missing from the "Copy Bundle Resources" section of Build Phases.
MainMenuViewController *mainMenu = [[MainMenuViewController alloc] init];
Had you set view's frame of mainMenu?

Main AppDelegate not getting called in universal application for iphone

I am working on xcode project intended to make a universal app.With the window based application template i got 3 AppDelegate Methods.2 for both ipad and iphone each and 1 Main AppDelegate method.When i run it for ipad ,the Main AppDelegate method is being called but when i run it for iphone environment ,the Main AppDelegate is not getting called.So how to get the controller to Main Appdelegate method while running it for Iphone environment..??
Here is description..
I have 3 appdelegate methods ,viz.prjOUMAppDelegate(main appdelegate),prjOUMAppDelegate_iPhone(for iphone),prjOUMAppDelegate_iPad(for ipad)..
I have some common methods like creating folders and moving files written in prjOUMAppDelegate(main appdelegate)method.I want it to run everytime irrespective of device ,so that i can get my folders created and some files to be moved.Its working fine when i run it for ipad(i.e creating folders and moving files ) but when i change the environment to iphone ,the prjOUMAppDelegate(main appdelegate) method is not getting called..so i dont know where iam getting wrong..
Ok, Your question is really a confusing one. I think you are looking for something like this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = //Initialize the ViewController for iPhone environment
}
else {
self.viewController = //Initialize the ViewController for iPad environment
}
self.navigationController = [[UINavigationController alloc]
initWithRootViewController:self.viewController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
If this is not the answer you are looking for then please update your question with some code.

iPhone switch screen in xcode 4.2

I am new to iPhone app. I was told not to use Xcode storyboard for the app to be compatible with iOS4.3 and under.
Right now, I have 2 pages showing using a tabcontroller, however I am trying to add a page that loads up first when the program is started (i.e. a Login page), after authenticated the user will land on the first page of the 2 tabs.
What would I need to do? Should I create a MainWindow.xib file?
Thanks!
James
You have (at least) two solutions. You can :
*Create the window the the didFinishLaunching function in your AppDelegate, with something like that:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *controller = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
self.navigationController.delegate = controller;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
*or you can create the MainWindow.xib file with the AppDelegate and the window, and tell your app use this nib when launched. To do that :
In the .plist, enter MainWindow for the "Main nib file base name" characteristic.