UITabBar iAd Banner Not Loading Properly After Changing View

| | August 11, 2015

I got a UITabBar and in each View there’s a iAd Banner.
Everything works fine the first time I select a view, but when I change view and than I go back to the first one, the iAd Banner doesn’t load properly (It’s white and shows the iAd Logo on the right corner) and I get this error: The operation couldn’t be completed. Ad was unloaded from this banner.

After about 15 seconds the Banner loads the Ad

Here’s the code to load the banner (It’s the same in every view)

@property (nonatomic, strong) ADBannerView *banner;

In viewDidLoad

self.banner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-29-50, self.view.bounds.size.width, 50)];
self.banner.delegate = (id)self;

[self.view addSubview:self.banner];

and

-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
    NSLog(@"Ad Banner action did finish");
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
    NSLog(@"Ad Banner did load ad.");

    [UIView animateWithDuration:0.5 animations:^{
        self.banner.alpha = 1.0;
    }];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
    NSLog(@"Unable to show ads. Error: %@", [error localizedDescription]);

    [UIView animateWithDuration:0.5 animations:^{
        self.banner.alpha = 0.0;
    }];
}

One Response to “UITabBar iAd Banner Not Loading Properly After Changing View”

  1. In your viewWillAppear set your ADBannerView‘s alpha initially to 0:

    -(void)viewWillAppear:(BOOL)animated {
        self.banner.alpha = 0.0;
    }
    

    This way when you reload the old view your ADBannerView will be hidden until it receives an ad from the iAd network again.

    A better approach would be to use a Shared iAd Banner across your entire application.

Leave a Reply