Question

My advertisement banner is replaced with a white banner when there is no content to display. Is there any reason for this based on the code provided? Also, is there anyway to properly supplement the banner with AdMob when iAd is unavailable?

//iAd Advertising
#pragma mark iAd Delegate Methods

- (void) bannerViewDidLoadAd:(ADBannerView *)banner {

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];

}

- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
    advertisement.hidden = YES;


}

I had tried this as far as supplementing it with Google AdMob:

#pragma mark iAd Delegate Methods

- (void) bannerViewDidLoadAd:(ADBannerView *)banner {

    advertisement.hidden = NO;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
    bannerView_.hidden = YES;

} // if there is an internet connection, load the iAd with a 1 second fade in effect

- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

    //MAKE SURE THIS IS RIGHT OR FIGURE OUT HOW TO MAKE IT RIGHT 

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
    advertisement.hidden = YES; 

    //2
    bannerView_.hidden = NO;
    bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 20, 320, 50)];
    bannerView_.adUnitID = @"//ca-app-pub-";
    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];
    [bannerView_ loadRequest:[GADRequest request]];

}

Was I wrong to make outlets of the bannerviews and have them hidden or shown? It doesn't work, it always only shows one of the advertisements, and as stated before, when iAd isn't there it only shows a white banner with nothing in it, which is intrusive and not cosmetic for the app's purpose.

Based on this, what have I done wrong? For both cases that is, why does the iAd show a white banner, and why does the AdMob not supplement itself.

Was it helpful?

Solution 2

If you set the alpha to 0 in storyboards, this will allow your code you've already used to work. Had the same problem.

OTHER TIPS

In StoryBoard, set your banner to hidden. In your viewController (the one define as delegate for the banner), put this code :

 - (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    [banner setHidden:false];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"Error : %@",error.description);
    [banner setHidden:true];
}

It looks like in didFailToReceiveAdWithError: you should be animating the banner alpha to zero but you're actually animating it to one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top