Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google ad click through issue in modal view #30

Closed
Fred10932 opened this issue Feb 1, 2013 · 18 comments
Closed

Google ad click through issue in modal view #30

Fred10932 opened this issue Feb 1, 2013 · 18 comments

Comments

@Fred10932
Copy link

Clickthrough on google ads works in root view, but not in modal views behind the root controller, instead I get a warning:

Warning: Attempt to present GADBrowserController: 0x1751e950> on MainViewController: 0x95a6ae0> whose view is not in the window hierarchy!

However, if I click though an iAd first in a modal view, close the browser window, and subsequently a google ad appears, clicking through the Google ad suddenly works.

@larsacus
Copy link
Owner

larsacus commented Feb 1, 2013

Can you explain what you mean by "behind the root controller"? The error you are getting is related to trying to display an ad that is not even in the visible view heirarchy.

@Fred10932
Copy link
Author

Root view controller -> iAd and Admob show and open browser when clicked
Root view controller >> Modal View -> iAd and Admob show but only iAd opens browser when clicked, admob error

After clicking on an iAd however, admob also opens browser when clicked in modal view

@larsacus
Copy link
Owner

larsacus commented Feb 2, 2013

Does the modal view have a view controller managing it?

@Fred10932
Copy link
Author

Yes, their own subclass of UIViewcontroller

@donrondo
Copy link

I've got the same problem.
Do you already have any solution Fred10932?

@larsacus
Copy link
Owner

A couple of questions:

  1. Where is the code located that is adding the ad to your view? viewDidLoad:? viewDidAppear:?
  2. How is your modal view controller being launched? Where in your code is it being called?

I'm asking because it sounds like something is wrong where you are launching the modal view or adding the ad to a view that is not on screen yet.

@donrondo
Copy link

Hi, thanks for your reply!

  1. I add my ad in: viewWillAppear: It is added with:
    [[LARSAdController sharedManager] addAdContainerToViewInViewController:self];

Should it be added in viewDidAppear:?

  1. I've got an UIButton which calls:
    [self presentViewController:modalViewController animated:NO completion:nil]

After some testing I was able to see more side effects:
Google AdMob works if its an ad linking directly to the appstore
Google AdMob doesn't work if it should open fullscreen. But my status bar disappears, so something must be happening.

Google says this must be a problem with the rootViewController property of my GADBannerView. It must set the rootviewcontroller to the one responsible for my modal view. But "addAdContainerToViewInViewController:self];" should do this, or am I wrong?

@larsacus
Copy link
Owner

Make sure your GoogleAds library is updated. Just googling what you're describing is bringing up a lot of old issues on google's admob forums that exactly describe the symptoms you're talking about.

@donrondo
Copy link

I already use the latest GoogleAds lib. 6.2.1.

@Fred10932
Copy link
Author

The problem is indeed that GADBrowserController tries to present itself on the parent VC of the modal VC, instead of on the modal VC itself. A simple way to check this is to load ads for the first time in the application on the modal VC instead of on its parent VC. Then everything works correctly.

How can we update the presenting VC of the GADBrowserController to the modal VC when the modal VC is loaded?

@Fred10932
Copy link
Author

@larsacus
Copy link
Owner

@Fred10932, that is the exact way that this class is constructed.

You should always be adding the ad controller to the presenting (visible) view controller and never a "root" view controller unless that root is your most-visible view controller.

@Fred10932
Copy link
Author

Yes, but somehow the setParentViewController method fails to properly update the rootViewController value of Google's bannerView when [[LARSAdController sharedManager] addAdContainerToViewInViewController:self]; is called in the modal VC's viewDidAppear.
Instead GADBrowserController keeps trying to present itself on the first VC in which [[LARSAdController sharedManager] addAdContainerToViewInViewController:self]; was called, in my case the root VC.

@larsacus
Copy link
Owner

If you can find a reason why it "fails to update" the rootViewController property, I'd be happy to accept a pull request.

Make sure that self in your above code is actually the view controller you are expecting, and not a different one, which would be causing these issues. You can pass any view controller you need to into that parameter, you don't have to always set self.

@Fred10932
Copy link
Author

It's a bug on Google's end (see https://groups.google.com/group/google-admob-ads-sdk/msg/c4a7da95d18a758d?dmode=source&output=gplain&noredirect&pli=1), which should be resolved in the next SDK release.

Meanwhile, the recommended workaround by Google is the following (see link posted 4msg ago):

Forwarding Delegate Notifications
An important note is that the AdMob SDK doesn’t let you change delegates after a request has been made. This means that if you switch view controllers after making an ad request, all GADBannerViewDelegate notifications will continue to be sent to the initial delegate (first view controller). A workaround for this is to make GADMasterViewController conform to the GADBannerViewDelegate protocol, then forward any notifications it receives to the correct view controller. This is the reasoning behind always setting currentDelegate_ in resetAdView:. Forwarding the notification takes minimal code. Here is an example of forwarding the adViewDidReceiveAd: notification:

  • (void)adViewDidReceiveAd:(GADBannerView *)view {
    // Make sure that the delegate actually responds to this notification
    if ) {
    [currentDelegate_ adViewDidReceiveAd:view];
    }
    }
    With these easy steps, your application is set up to use a singleton GADBannerView. If you have any questions about this topic or the SDK in general, feel free to post them in our forum or come join us in our upcoming office hours.

@donrondo
Copy link

@Fred10932
Have you tried implementing this solution? Is it working for you?

@Fred10932
Copy link
Author

@donrondo
I went another route: working with a nav controller now (no issues anymore with pushed view controllers).

@larsacus
Copy link
Owner

I'm still trying to wrapt head around why this isn't working. Based on the snippet above from the google thread, they are assuming that each view controller is conforming to their delegate protocol. This is not the case with this project since LARSAdController's adapters are acting as the delegate, which never changes, so it seems to not apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants