广告加载失败时,将iAd ADBannerView隐藏在Swift中-没有委托或委托未实现didFailToReceiveAdWithError [英] Hiding iAd ADBannerView in Swift when ad fails to load - no delegate or delegate does not implement didFailToReceiveAdWithError

查看:72
本文介绍了广告加载失败时,将iAd ADBannerView隐藏在Swift中-没有委托或委托未实现didFailToReceiveAdWithError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在使用的代码:

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")}

将iAd填充率设置为0%时,不会打印任何内容,并且会从控制台获得以下输出:

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

ADBannerView:未处理的错误(没有委托或委托未实现didFailToReceiveAdWithError :):错误Domain = ADErrorDomain代码= 5操作无法完成.横幅视图可见但不包含内容" UserInfo = 0x7fd3fd3335e0 {ADInternalErrorCode = 5,NSLocalizedFailureReason =横幅视图可见但不包含内容,ADInternalErrorDomain = ADErrorDomain}

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}

使用self.canDisplayBannerAds = true时,将调用

推荐答案

代理方法.您需要自己创建一个ADBannerView并将其delegate设置为要调用的委托方法,例如bannerView.delegate = self.

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是实施iAd标语的一种简便的方法.它将为您创建一个ADBannerView,如果收到广告将显示ADBannerView,如果没有收到广告则将其隐藏.以这种方式实现iAd标语时,无需实现委托方法.

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.

因此,您有两个选择,删除var bannerView = ADBannerView()并使用self.canDisplayBannerAds = true提供的iAd标语,或者删除self.canDisplayBannerAds = true并完成实现自己的ADBannerView.

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.

如果您决定实施自己的ADBannerView,请在此处查看我的回答,只需忽略AdMob实施.

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

这篇关于广告加载失败时,将iAd ADBannerView隐藏在Swift中-没有委托或委托未实现didFailToReceiveAdWithError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆