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

半世苍凉 提交于 2019-12-10 13:54:01

问题


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}


回答1:


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.



来源:https://stackoverflow.com/questions/30925672/hiding-iad-adbannerview-in-swift-when-ad-fails-to-load-no-delegate-or-delegate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!