AdMob iOS Integration Question

389 views
Skip to first unread message

Blockdot

unread,
Oct 6, 2011, 3:40:24 PM10/6/11
to Google AdMob Ads Developers
Hello,

I'm sure the answer to this will be really simple but for the life of
me I can't figure it out.

I have successfully integrated AdMob into two iOS applications. Now
I'm trying to integrate it into a third, and I'm having difficulty.

The application I am currently working with uses cocos2D and a
navigation controller. The navigation controller has a root view
controller which presents a series of other view controllers modally,
when appropriate. This works fine from a navigation and gameplay
standpoint, but is the only difference I can pinpoint between this app
and the previous two that could be causing this problem.

I have implemented the GADBannerViewDelegate methods. When I click
the test ad in the simulator, I receive adViewWillPresentScreen, just
as I should. But then nothing appears! Everything in my game
continues to run as before, as if I never clicked the ad at all.

So I KNOW that I am getting a touch event on the ad, and I KNOW that I
am receiving that adViewWillPresentScreen message. But nothing
happens graphically. What am I doing wrong? How can I fix this? I
would really appreciate any help anyone has to offer. It seems a bit
silly that I can implement this just fine in two apps but then some
small error is preventing me from doing it here.

Please email me if you have any ideas about what to do about this; my
email is wk...@blockdot.com.

Thank you!

-W

Rajkumar Parameswaran

unread,
Oct 6, 2011, 4:58:43 PM10/6/11
to google-adm...@googlegroups.com
Do you have a code snippet that shows us how you are setting your root view controller for the ad view? It sounds to me like something may be weird there. 

What view controller are you setting at the rootViewController for your ad view? Is this the top level view in your application when the ad is clicked?

Raj

Blockdot

unread,
Oct 7, 2011, 9:05:15 AM10/7/11
to Google AdMob Ads Developers
Will paste in some code snippets for you. The view controller I'm
setting for the ad is indeed the top level view. As you can see, I
create the view controller, call a function to set that view
controller as the ad's root view controller, and then use my
navigation controller to present that view controller modally. The ad
shows up just fine and I'm receiving the adViewWillPresentScreen
message but... Then nothing happens. If you have any idea what I'm
doing wrong that would be great : )

In the code snippets, understand that AdMobObjects is a singleton
class and 'instance' is the method which returns a pointer to the
singleton instance of the class.


//In my cocos2d layer:
-(void) initPlayGameState
{
if(!playGameCtrlr)
{
playGameCtrlr = [[PlayGameViewController alloc] init];
}

[self setupAdMobAd:playGameCtrlr];

[[ENVAR getNavigationController]
presentModalViewController:playGameCtrlr animated:YES];
}

//Also in my cocos 2d layer:
-(void) setupAdMobAd:(UIViewController*)viewCtrlr;
{
[[AdMobObjects instance] setViewCtrlr:viewCtrlr];
[[AdMobObjects instance] displayAd];
}

//In my AdMobObjects class:
-(void) setViewCtrlr:(id)ctrlr
{
mViewCtrlr = ctrlr;
}

//Also in my AdMobObjects class:
-(void) displayAd
{

bannerView.rootViewController = mViewCtrlr;
GADRequest* testRequestB = [GADRequest request];
testRequestB.testDevices = [NSArray
arrayWithObjects:GAD_SIMULATOR_ID, nil]; //request a test ad when
on simulator
[[[AdMobObjects instance] getBannerView]
loadRequest:testRequestB];

[mViewCtrlr.view addSubview:bannerView]; //add banner
view to view ctrlr's view
[mViewCtrlr.view bringSubviewToFront:bannerView]; //bring it to
front
}

You have no idea how grateful I would be if you could tell me what I'm
doing wrong!!

Thanks so much,

-W

Rajkumar Parameswaran

unread,
Oct 10, 2011, 5:12:27 PM10/10/11
to google-adm...@googlegroups.com
Hmm, I'm trying to reproduce your issue but for some reason that ad seems to be showing for me. Where in your view hierarchy is the navigation controller? 

I added a navigation controller as a subview into [[CCDirector sharedView] openGLView] and then presented a view controller modally from that navigation controller. The ad seems to be displaying fine this way in the simulator though. 

In displayAd, is there a specific reason that you call loadRequest on [[AdMobObjects instance] getBannerView] and not just bannerView?

Do you have any other information that can help me reproduce the issue?

Raj

Blockdot

unread,
Oct 11, 2011, 1:50:45 PM10/11/11
to Google AdMob Ads Developers
I will make a copy of my project and try your way for the view
hierarchy. What I did was this in my app delegate. rootViewCtrlr and
navigationCtrlr are member variables of my app delegate. Am I doing
something wrong here?

rootViewCtrlr = [[RootViewController alloc] init];
rootViewCtrlr.wantsFullScreenLayout = YES;
[rootViewCtrlr setView:glView]; // make the
OpenGLView a child of the view controller

navigationController = [[UINavigationController alloc]
initWithRootViewController:rootViewCtrlr];
navigationController.navigationBarHidden = true; //
hides the weird gray bar at the top
navigationController.delegate = rootViewCtrlr;

rootViewCtrlr.parentNavigationController =
navigationController; //the root view controller needs a pointer to
the navigation controller

window.rootViewController = navigationController; //
make the navigation Controller a child of the main window



The reason I called [[AdMobObjects instance] getBannerView] is because
this functionality used to be in another class and I moved it; I guess
I never changed it. Thanks for pointing it out, I'll change it
now : )

Does the above code snippet help you figure out my problem? : )

Thanks!!

-W

Rajkumar Parameswaran

unread,
Oct 11, 2011, 9:13:38 PM10/11/11
to Google AdMob Ads Developers
Hmm that is weird, I'm able to reproduce the issue and am trying to
see if we can find out why it's happening.

In the meantime though, in your app does it change functionality
radically if you were to call pushViewController: instead of
presentModalViewController: on your viewcontroller (this change seems
to work for me but I don't know if the design of your app will allow
for this). Another way I'm getting the ad to show is by commenting out
the window.rootViewController line and just using addSubview there
instead (don't know if any of these temporary fixes can help you while
we try to get to the bottom of the issue).

Raj

Blockdot

unread,
Oct 12, 2011, 9:54:47 AM10/12/11
to Google AdMob Ads Developers
Unfortunately it does change the functionality of my app if I were to
use pushViewController: instead of presentModalViewController:. I am
a bit confused about your second suggestion; I tried typing it out as
I thought you meant:

[window addSubview:navigationController];

And I get a warning, "Incompatible pointer types sending
'UINavigationController*' to parameter of type 'UIView*'." Which
makes sense, really, since the nav controller isn't a view. Is that
what you meant or am I misinterpreting?

I'm glad you can reproduce the error, though, because it means I'm not
crazy! I was afraid I'd done something really silly. Thanks for your
continuing help and I hope we can figure out what's wrong with it
soon : )

-W

Blockdot

unread,
Oct 12, 2011, 9:56:13 AM10/12/11
to Google AdMob Ads Developers
As a quick update, I attempted running the program with the line
above:

[window addSubview:navigationController];

and the program crashed with SIGABRT.

-W

Rajkumar Parameswaran

unread,
Oct 12, 2011, 6:24:33 PM10/12/11
to Google AdMob Ads Developers
Have you tried:

[window addSubview:navigationController.view];

Raj

Blockdot

unread,
Oct 13, 2011, 12:20:38 PM10/13/11
to Google AdMob Ads Developers
The problem with that is that my navigation controller no longer has
control of the application. I won't be able to use it to push my view
controllers anymore, there will just be a starter view on my window.

-W

Blockdot

unread,
Oct 13, 2011, 12:21:39 PM10/13/11
to Google AdMob Ads Developers
Is there any way to directly access the expanded ad view and manually
add it to the view when the ad is clicked? Since it is not handling
this behavior itself that seems to be the best solution.

-W

Blockdot

unread,
Oct 17, 2011, 9:48:21 AM10/17/11
to Google AdMob Ads Developers
Do you have any advice for something I can do that will work?

Thanks,

-W

Rajkumar Parameswaran

unread,
Oct 17, 2011, 8:27:42 PM10/17/11
to Google AdMob Ads Developers
I don't understand why if you did

[self.window addSubview:navigationController.view]

versus

self.window.rootViewController = navigationController

it would be any different in terms of pushing view controllers from
the navigation controller? I know rootViewController is iOS 4.0+ only
and it does give you some extra functionality but I didn't know that
it affects whether you can push view controllers from them? (you
should still be able to access the navigation controller using
self.navigationcontroller from a viewcontroller no?)

Raj

Rajkumar Parameswaran

unread,
Oct 19, 2011, 2:07:49 PM10/19/11
to Google AdMob Ads Developers
To follow up with you, it looks like this is actually a bug with the
SDK.

We are fixing the issue and we plan to push that fix into the iOS5
compatible SDK which we will release soon.

Raj

Blockdot

unread,
Oct 21, 2011, 5:28:11 PM10/21/11
to Google AdMob Ads Developers
Raj,

Can you give me an example of what you mean in your post from the
17th? I don't see how this would work; maybe a code snippet would
clarify. If in the window I simply
addSubview:navigationController.view, the navigation controller has
not been bound to my window, right? Only its view has been bound do
the window. So which view controller are you suggesting I am then
able to push other view controllers from modally? The window is not
tied to a navigation controller, so I cannot get the navigation
controller's rootViewController and use that to push other view
controllers...where would they push to?

Also I'm pretty sure navigationController would just have a view
controller as a property, not a view?

So if you could provide a code snippet that would be great.
Unfortunately this app will not be iOS5 compatible so I will not be
able to upgrade to the iOS5 SDK you mentioned; also the release date
is sooner than it is probably reasonable to expect you to release your
SDK.

Thanks,

-W

Rajkumar Parameswaran

unread,
Oct 21, 2011, 6:21:18 PM10/21/11
to Google AdMob Ads Developers
I think that the view property for a navigation controller is just a
container for several other views. Essentially, UINavigationController
extends UIViewController so it has a view property which is just the
root of the view hierarchy you create. This is why if you do something
like:

[window addSubview:navigationController.view]

it is the same thing (almost) as doing

window.rootviewController = navigationController

I thought that they are both bounding your view to the window.

I'm just reading this under the "Navigation Controller Views" heading
at http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html.

In your view controller then, you should be able to actually access
the navigation controller by using self.navigationController (I think
you can only do this in the view lifecycle from viewDidLoad onwards).
Let me know if that made things any clearer.

Raj

Blockdot

unread,
Oct 31, 2011, 2:24:14 PM10/31/11
to Google AdMob Ads Developers
Unfortunately this suggestion did not work for me. When I use [window
addSubview:navigationController.view], nothing happens to the screen
at all; I simply get a black page. When I try to manually set the
views, ie. if the view controller I want to display is:

UIViewController* mMainMenuController;

Then I try this:

[window addSubview:mMainMenuController.view];

And the view appears but nothing is functional (buttons are no longer
clickable) and the background does not show up, because the background
is bound to the view CONTROLLER, not the view itself. So this
solution is not working for me. What other suggestions do you have?
Are you sure there is nothing I can do directly with the AdMob code to
make this work?

When will the iOS5 SDK be out? I do not think it will be before this
project's release date but it is possible.

Thanks,

-W

On Oct 21, 5:21 pm, Rajkumar Parameswaran <rajp...@google.com> wrote:
> I think that the view property for a navigation controller is just a
> container for several other views. Essentially, UINavigationController
> extends UIViewController so it has a view property which is just the
> root of the view hierarchy you create. This is why if you do something
> like:
>
> [window addSubview:navigationController.view]
>
> it is the same thing (almost) as doing
>
> window.rootviewController = navigationController
>
> I thought that they are both bounding your view to the window.
>
> I'm just reading this under the "Navigation Controller Views" heading
> athttp://developer.apple.com/library/ios/#documentation/uikit/reference....

Rajkumar Parameswaran

unread,
Oct 31, 2011, 2:27:44 PM10/31/11
to Google AdMob Ads Developers
We actually released Google AdMob Ads SDK iOS v5.0.4 last week so I'd
recommend trying this version out to see if your problem is fixed.

Raj

David

unread,
Oct 31, 2011, 2:26:55 PM10/31/11
to google-adm...@googlegroups.com
Admob IOS 5 SDK has been out for quite awhile.

http://code.google.com/mobile/ads/download.html

It's even got an update to 5.0.4

Blockdot

unread,
Nov 1, 2011, 8:55:36 AM11/1/11
to Google AdMob Ads Developers
Excellent! Thanks, I am very happily surprised by how quick that
was! I imagined it would take much more time for you to be able to
revise your SDK. Thanks very much!

My ad's full screen view does in fact appear now, so this is great
news. Thanks very much for all your help and support, and I'm so glad
that my ads are working properly now!

Thanks again,

-W
Reply all
Reply to author
Forward
0 new messages