Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding iAd ADBannerView in Swift when ad fails to load - no delegate or delegate does not implement didFailToReceiveAdWithError

Tags:

ios

swift

iad

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}

like image 637
dwinnbrown Avatar asked Sep 28 '22 14:09

dwinnbrown


1 Answers

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.

like image 107
Daniel Storm Avatar answered Nov 15 '22 06:11

Daniel Storm