1

I have a little problem with iAd. Sometimes it shows a blank white box. When I try it with Admob it works perfect. Sometimes the banner comes correctly from the button but sometimes it shows the white box immediately. What is the issue?

Here is my code:

    -(void)viewDidLayoutSubviews
    {
        if (self.view.frame.size.height != self.iAdBannerView.frame.origin.y)
                    {
            self.iAdBannerView.frame = CGRectMake(0.0, self.view.frame.size.height, self.iAdBannerView.frame.size.width, self.iAdBannerView.frame.size.height);
                                    iAdBannerView.requiredContentSizeIdentifiers= [NSSet setWithObjects: ADBannerContentSizeIdentifierLandscape,nil];
                        iAdBannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
                    }

            if (self.view.frame.size.height != self.gAdBannerView.frame.origin.y)
            {
                self.gAdBannerView.frame = CGRectMake(150, self.view.frame.size.height, self.gAdBannerView.frame.size.width, self.gAdBannerView.frame.size.height);
            }

// Hide the banner by sliding down
-(void)hideBanner:(UIView*)banner
{
    if (banner && ![banner isHidden])
    {
        [UIView beginAnimations:@"hideBanner" context:NULL];
        banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
        [UIView commitAnimations];
        banner.hidden = TRUE;
    }
}

// Show the banner by sliding up
-(void)showBanner:(UIView*)banner
{
    if (banner && [banner isHidden])
    {
        [UIView beginAnimations:@"showBanner" context:NULL];
        banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
        [UIView commitAnimations];
        banner.hidden = FALSE;
    }
}

#pragma mark - ADBanner delegate methods -

// Called before the add is shown, time to move the view
- (void)bannerViewWillLoadAd:(ADBannerView *)banner
{
    NSLog(@"iAd load");
    [self hideBanner:self.gAdBannerView];
    [self showBanner:self.iAdBannerView];
}

// Called when an error occured
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"iAd error: %@", error);
    [self hideBanner:self.iAdBannerView];
    [self.gAdBannerView loadRequest:[GADRequest request]];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

iAds doesn't always load an ad. There's a delegate method to let you know when an ad loads successfully.

ADBannerViewDelegate has bannerViewDidLoadAd: and bannerView:didFailToReceiveAdWithError:.

jab
  • 4,053
  • 3
  • 33
  • 40
  • i added the Delegate ahead – Wollknäuel Sockenbart Dec 09 '13 at 23:37
  • Are the delegate methods being called? Is it different between when the ad shows correctly and when it doesn't? – jab Dec 09 '13 at 23:49
  • Did you look at [this](http://stackoverflow.com/questions/13103315/iad-banner-not-working) or [this](http://stackoverflow.com/questions/10312196/iads-sometime-appearing-as-white-boxes-in-app)? – jab Dec 09 '13 at 23:51
  • when it works correctly the banner slides from the bottom and when it does´t work correctly a have a white box at the bottom and some seconds later it fills it with the iAd test Text. The other solution doesn't work for me :( – Wollknäuel Sockenbart Dec 09 '13 at 23:59
  • 1
    I think what's happening is you're getting neither an ad nor a failure, hence you see nothing. You need to have something in that space when the banner is hidden, and initialize it in that state. – jab Dec 10 '13 at 00:29