3

I have a Test application setup with AdMob Mediation service being used, only on testing device at the moment. I have setup all the required methods per the documentation. I am having an issue where when the Fail to Receive Ad error occurs, no more ads are requested or shown?

Header:

#import <UIKit/UIKit.h>
#import "GADBannerViewDelegate.h"

@class GADBannerView, GADRequest;

@interface AdTestViewController : UIViewController
    <GADBannerViewDelegate> {
    GADBannerView *bannerView_;
}

@property (nonatomic, retain) GADBannerView *bannerView;

- (GADRequest *)createRequest;

@end

Imp File

#import "AdTestViewController.h"
#import "Constants.h"
#import "GADBannerView.h"
#import "GADRequest.h"

@implementation AdTestViewController

@synthesize bannerView = bannerView_;

- (void)viewDidLoad {
    [super viewDidLoad];

    // Create a view of the standard size at the top of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    //bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    // Initialize the banner at the bottom of the screen.
    //CGPoint origin = CGPointMake(0.0,
     //                            self.view.frame.size.height -
       //                          CGSizeFromGADAdSize(kGADAdSizeBanner).height);
    self.bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
                                                    //origin:origin];

    self.bannerView.adUnitID = kAdMobPublisherID;
    self.bannerView.delegate = self;
    [self.bannerView setRootViewController:self];
    [self.view addSubview:self.bannerView];
    self.bannerView.center =
    CGPointMake(self.view.center.x, self.bannerView.center.y);
    [bannerView_ loadRequest:[self createRequest]];

    bannerView_.backgroundColor = [UIColor blueColor];


    // Make the request for a test ad. Put in an identifier for
    // the simulator as well as any devices you want to receive test ads.
    GADRequest *request = [GADRequest request];
    request.testDevices = [NSArray arrayWithObjects:
                           @"4D047EB9-A3A7-441E-989E-C5437F05DB04",
                           @"YOUR_DEVICE_IDENTIFIER",
                           nil];

}

- (GADRequest *)createRequest {
    GADRequest *request = [GADRequest request];

    // Make the request for a test ad. Put in an identifier for the simulator as
    // well as any devices you want to receive test ads.
    request.testDevices = [NSArray arrayWithObjects:
                           @"4D047EB9-A3A7-441E-989E-C5437F05DB04",
                           @"YOUR_DEVICE_IDENTIFIER",
                           nil];
    return request;
}

- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error;
{
    NSLog(@"Error - did Fail to Receive an Ad");
    bannerView_.hidden = YES;

}

- (void)adViewDidReceiveAd:(GADBannerView *)view;
{
    NSLog(@"Ad Received");
    bannerView_.hidden = NO;
}

@end

What I am seeing in my logs is the 'Ad Received' a few times, then 'Error - did Fail to Receive an Ad'... After this log there are no further entries it is like it stops requesting? Testing only on simulator at present.

Any ideas how to solve this, or potentially an alternative method on hiding the view when an error/no ad is received?

StuartM
  • 6,743
  • 18
  • 84
  • 160

5 Answers5

1

I find the same thing – when the GADBannerView is hidden, no more requests are sent out.

One thing I tried successfully is to move the GADBannerView offscreen instead of hiding it. Of course, you only want to do this as a consequence of didFailToReceiveAdWithError, and then move it back onscreen when adViewDidReceiveAd. I got this working so the user sees a nice animation when ads come and go, much like iAd encourages.

In short, the code below will place your GADBannerView (here called mAdBannerView) either at the bottom of the screen or offscreen, depending on the boolean adIsLoaded.

  CGRect bannerFrame = mAdBannerView.frame;
  bannerFrame.origin.y = self.view.bounds.size.height - (adIsLoaded * bannerFrame.size.height);
  mAdBannerView.frame = bannerFrame;
Mischinab
  • 2,751
  • 1
  • 20
  • 15
0

in the method that's called when there is an error put in some thing like

bannerView_.hidden = 1;

that will hide the view if there's an error and it will probably automatically be displayed if an ad was received with no error

Chris Loonam
  • 5,735
  • 6
  • 41
  • 63
0

Think you're better off just hiding the bannerView_ with the hidden property.

- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
        bannerView_.hidden = YES;       
    }

Of course you have to remember to set hidden back to YES when an ad is successfully received.

RajPara
  • 2,281
  • 1
  • 16
  • 9
  • This partly works. It hides the ad, but once the bannerView is hidden after the first error... no other ads are fed? It is like when the view is hidden, it does not request for ads anymore, is there an alternative? – StuartM Jan 27 '13 at 20:49
0

Simple solution, set the bannerView_.hidden true in adView:didFailToReciewvwAdWithError method. And to retrieve the view use adViewDidReceiveAd method. Example code:

These are ADmob's delegate method:

- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error
{
    bannerView_.hidden = YES;
}

- (void)adViewDidReceiveAd:(GADBannerView *)view
{
    bannerView_.hidden = NO;
}
Shabib
  • 1,697
  • 4
  • 20
  • 39
  • This partly works. It hides the ad, but once the bannerView is hidden after the first error... no other ads are fed? It is like when the view is hidden, it does not request for ads anymore, is there an alternative? – StuartM Jan 27 '13 at 20:49
  • are you using 'GoogleAdMobAdsSDKiOS-5.0.5' or later version? because the 'adViewDidReceiveAd:' is in that version and later. if you're using using any previous version please update your admob sdk. – Shabib Jan 28 '13 at 08:28
  • The method is in the version of the SDK that I use because if I log for both receive and failtoreceive I see entries in console. I.e. did receive, did receive, fail to receive... then no further entries – StuartM Jan 28 '13 at 11:00
  • It is exactly as within the question expect now has NSLog(@"Error - did Fail to Receive an Ad"); for did fail, and a Log for didreceive. I see the did receive and fail in the log, but once the fail occurs no more action happens in terms of ads – StuartM Jan 28 '13 at 16:13
  • I have updated the question with more information and a picture to show. I think the issue relates to the delegate as opposed to the methods/hiding. – StuartM Jan 28 '13 at 21:30
0

I had the same problem, this worked for me:

Do not use the .hidden property to hide AdMob ads. Just set the alpha to 0 (invisible) or 1 (visible).

So in your GADBannerView delegate method...

-(void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)error {

    // Hide the ad banner.
    [UIView animateWithDuration:0.5 animations:^{

        self.myADBanner.alpha = 0.0;

    }];

}

-(void)adViewDidReceiveAd:(GADBannerView *)bannerView {

    //Show the ad banner.
    [UIView animateWithDuration:0.5 animations:^{

        self.myADBanner.alpha = 1.0;

    }];

}

With regards to "After this log there are no further entries it is like it stops requesting?"

This happens to me as well when I remove an ad from the view hierarchy. However, requests continue when I add the ad back to the view hierarchy. The only time they didn't continue was when I was using the .hidden property.

RS-232
  • 1
  • 2