5

This is the code I am using:

var bannerView = ADBannerView()
self.canDisplayBannerAds = true

//show ad banner if an ad loads
func bannerViewDidLoadAd(banner: ADBannerView!)
{bannerView.hidden = false}

//hide ad banner if the ad fails to load
func bannerViewFailsToLoadAd(banner: ADBannerView!,didFailToReceiveAdWithError error: NSError!)
{bannerView.hidden = true
 println("failed to receive ad")}

When I set the iAd fill rate to 0% nothing is printed and I get this output from the console:

ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=5 "The operation couldn’t be completed. Banner view is visible but does not have content" UserInfo=0x7fd3fd3335e0 {ADInternalErrorCode=5, NSLocalizedFailureReason=Banner view is visible but does not have content, ADInternalErrorDomain=ADErrorDomain}

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
dwinnbrown
  • 3,789
  • 9
  • 35
  • 60

1 Answers1

4

Delegate methods will not be called when using self.canDisplayBannerAds = true. You need to create an ADBannerView yourself and set its delegate for the delegate methods to be called, for example, bannerView.delegate = self.

self.canDisplayBannerAds = true is a no hassle way of implementing iAd banners. It will create an ADBannerView for you, display it if it receives an ad, and hide it if it does not receive an ad. There is no need to implement delegate methods when implementing your iAd banner in this way.

So you have two options, remove var bannerView = ADBannerView() and use the iAd banner that self.canDisplayBannerAds = true provides, or remove self.canDisplayBannerAds = true and finish implementing your own ADBannerView.

If you decide to implement your own ADBannerView check my answer here, just ignore the AdMob implementation.

Community
  • 1
  • 1
Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
  • @Daniel_Storm Ok. Just so that I am understanding correctly can you confirm the if I just use the self.canDisplayBannerAds = true the banner section would hide if it failed to load? – dwinnbrown Jun 19 '15 at 10:30
  • @dwinnbrown Yes, when using `self.canDisplayBannerAds = true` if the banner is unable to receive an ad from the iAd network it will move itself off the screen. Set the fill rate to 50% in the settings on your device and watch the `ADBannerView` display and hide as it receives and fails to receive ads. – Daniel Storm Jun 19 '15 at 10:32
  • I tried that but I am still left with a white rectangle which when tapped just highlights grey – dwinnbrown Jun 19 '15 at 10:48
  • 1
    @dwinnbrown did you add an `ADBannerView` to your storyboard by chance? If so, delete it. – Daniel Storm Jun 19 '15 at 11:46
  • 1
    @Daniel_Storm Ah that was it thank you so much it is working perfectly now! – dwinnbrown Jun 19 '15 at 12:09
  • 1
    @DanielStorm this whole time my banners were going white and now I know why! – yaboi Oct 21 '15 at 05:47