larsacus / LARSAdController

Lightweight ad mediation for iOS to properly manage multiple ad networks dynamically including iAd and Google ads.
http://theonlylars.com/blog/2013/01/10/stupid-easy-ads-with-larsadcontroller-3-dot-0/
MIT License
269 stars 60 forks source link

Google adapter complaining about not setting root view controller #28

Closed walsht closed 11 years ago

walsht commented 11 years ago

Google adapter complaining about not setting root view controller. So, I added this line in TOLAdAdapterGoogleAds: - (GADBannerView *)bannerView{

    [_bannerView setRootViewController:[self parentViewController]];

Not showing issue all the time and not sure if it would work for all uses, but works for me.

larsacus commented 11 years ago

The code path looks correct and the root view controller is getting set properly on the google ads when it is getting created. The only thing I can think of is that the reference to the root view controller in all contexts is a weak reference. This means that if the view controller that the ads are currently hosted in gets deallocated by the system and cleaned up, this warning could result.

As of now, I can find nothing wrong with the code-path relating to setting the root view controller.

larsacus commented 11 years ago

After looking at this further, it looks like this may have been possible when adding an ad to a new view controller. Check out commit e7ff542 to see if this resolves the issue.

walsht commented 11 years ago

Still getting the warning. The problem is that it never recovers and shows a ad.

I am only showing Google Ads, may have something to do with it? Or, it looks like I am only getting this in the ipad simulator.

Thanks.

Here are the logs: 2013-01-29 05:43:20.734 MyApp[57559:c07] -[AppDelegate application:didFinishLaunchingWithOptions:] line 25 $ 2013-01-29 05:43:20.943 MyApp[57559:c07] LARSAdController [line 184]: View is portrait 2013-01-29 05:43:20.944 MyApp[57559:c07] LARSAdController [line 207]: Container frame: {{0, 914}, {768, 90}} 2013-01-29 05:43:20.944 MyApp[57559:c07] LARSAdController [line 520]: Creating new instance of adapter class "TOLAdAdapterGoogleAds" 2013-01-29 05:43:20.974 MyApp[57559:c07] LARSAdController [line 560]: Successfully created instance of "TOLAdAdapterGoogleAds" 2013-01-29 05:43:20.974 MyApp[57559:c07] LARSAdController [line 471]: Initial banner frame : {{0, 90}, {768, 90}} 2013-01-29 05:43:20.975 MyApp[57559:c07] LARSAdController [line 496]: Final banner frame : {{0, 0}, {768, 90}} 2013-01-29 05:43:20.975 MyApp[57559:c07] LARSAdController [line 701]: Registering for orientation notifications 2013-01-29 05:43:20.976 MyApp[57559:c07] LARSAdController [line 184]: View is portrait 2013-01-29 05:43:21.012 MyApp[57559:c07] LARSAdController [line 207]: Container frame: {{0, 914}, {768, 90}} 2013-01-29 05:43:21.013 MyApp[57559:c07] LARSAdController [line 496]: Final banner frame : {{0, 0}, {768, 90}} 2013-01-29 05:43:21.026 MyApp[57559:c07] LARSAdController [line 727]: Handling orientation change 2013-01-29 05:43:21.137 MyApp[57559:c07] LARSAdController [line 727]: Handling orientation change 2013-01-29 05:43:21.138 MyApp[57559:c07] LARSAdController [line 184]: View is portrait 2013-01-29 05:43:21.138 MyApp[57559:c07] LARSAdController [line 207]: Container frame: {{0, 914}, {768, 90}} 2013-01-29 05:43:21.139 MyApp[57559:c07] LARSAdController [line 496]: Final banner frame : {{0, 0}, {768, 90}} 2013-01-29 05:43:21.139 MyApp[57559:c07] LARSAdController [line 184]: View is portrait 2013-01-29 05:43:21.139 MyApp[57559:c07] LARSAdController [line 207]: Container frame: {{0, 914}, {768, 90}} 2013-01-29 05:43:21.140 MyApp[57559:c07] LARSAdController [line 496]: Final banner frame : {{0, 0}, {768, 90}} 2013-01-29 05:43:22.460 MyApp[57559:c07] LARSAdController [line 727]: Handling orientation change 2013-01-29 05:43:22.469 MyApp[57559:c07] LARSAdController [line 175]: View is landscape 2013-01-29 05:43:22.469 MyApp[57559:c07] LARSAdController [line 207]: Container frame: {{0, 658}, {1024, 90}} 2013-01-29 05:43:22.480 MyApp[57559:c07] LARSAdController [line 496]: Final banner frame : {{0, 0}, {1024, 90}} 2013-01-29 05:43:24.305 MyApp[57559:c07] Must set the rootViewController property of GADBannerView before calling loadRequest:

larsacus commented 11 years ago

Are you changing view controllers when this happens? It looks like you're changing orientations, does this always happen only when you change orientations? If you could do some debugging and find out exactly if the parentViewController property is actually nil, or is simply never getting assigned to the bannerView.

walsht commented 11 years ago

Just doing some testing on the AdMob banner example and found that it looks like it has to do with [self.bannerView setNeedsLayout];

If I call this before [_bannerView loadRequest:request];

It is fine, but after it gives me the warning.

Hope this helps.

larsacus commented 11 years ago

The admob banner example as in the vanilla Google AdMob example code from Google's site? Or my sample project?

There is absolutely no reason why setNeedsLayout would affect the rootViewController's property unless it's a bug within Google's framework.

walsht commented 11 years ago

I was testing using the Google AdMob example code, when I mess with the setNeedsLayout I was getting the issue. Looks like your code is working fine on the devices, just a simulator issue.

I have decided to build my own add display. If you could add the ability to have iAd display if successful over Admob, I may add that into future projects. I just get better revenue from iAD if it is available.

Thanks, TIm

larsacus commented 11 years ago

The framework as it is will support whatever ad network priority you would like to define. If you would like to have iAd always display first, then simply register the ad adapters in this order:

[[LARSAdController sharedManager] registerAdapterClass:[TOLAdAdapteriAds class]];
[[LARSAdController sharedManager] registerAdapterClass:[TOLAdAdapterGoogleAds class]];

This tells the ad controller that you always want iAds to display when they are available and to display AdMob ads when there are no iAds. It will fill the gaps in depending on what priority you register them in.

walsht commented 11 years ago

I see, and didn't know that. Few other things that would be helpful:

Thanks, Tim

larsacus commented 11 years ago

I'd be happy to entertain a pull request with this functionality added.