iAd 横幅在 segue 上变白

iAd banner goes white on segue

我正在使用 Xcode 7,Swift 2.0。这个问题既发生在模拟器中,也发生在我在 App Store 上可用的实际应用程序中。很多时候(不总是),当我在我的应用程序中执行 segue 时,adBanner 在加载新广告之前会变成纯白色。我很困惑,因为有广告可用,即使它是白色的!

这是我的代码:

我初始化ADBannerView:

var adBanner = ADBannerView(adType: ADAdType.Banner)

在我看来DidLoad:

self.canDisplayBannerAds = true
self.adBanner.delegate = self
self.adBanner.hidden = true
self.adBanner.alpha = 0
self.adBanner.frame.origin.y = self.view.frame.height-self.adBanner.frame.height
self.view.addSubview(self.adBanner)

我的 viewDidDisappear:

override func viewDidDisappear(animated: Bool) {

        super.viewDidDisappear(true)

        adBanner.removeFromSuperview()

        if( deviceType.isEqualToString("iPhone") )
        {

            adBanner.delegate = nil

        }

    }

在我的 class:

    func bannerViewDidLoadAd(banner: ADBannerView!)
    {

        self.adBanner.hidden = false
        UIView.animateWithDuration(0.5, animations: {self.adBanner.alpha = 1})

    }

    func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!)
    {
        self.adBanner.hidden = true
        UIView.animateWithDuration(0.5, animations: {self.adBanner.alpha = 0})

    }

    func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool
    {

        return willLeave

    }

    func bannerViewWillLoadAd(banner: ADBannerView!) {

    }

当 运行 使用 Xcode 的应用程序时,尽管我已经实现了委托方法,但我偶尔会收到此消息:

ADBannerView:未处理的错误(没有委托或委托未实现 didFailToReceiveAdWithError:):错误域=ADErrorDomain 代码=5 "The operation couldn’t be completed. Banner view is visible but does not have content" 用户信息=0x9632d30 {ADInternalErrorCode=5,NSLocalizedFailureReason=横幅视图可见但不可见有内容}

编辑:问题是使用 canDisplayBannerAds 导致未调用委托方法。更多信息在这里:

这里有一些适用于你的工作代码,我刚刚工作过。这不需要 self.candisplaybannerads = true 因为我有一些问题。广告会根据屏幕尺寸自动改变尺寸,位于屏幕底部。在我的spritekit游戏中,过渡时变白没有任何问题。

import iAd

class viewController: UIViewController, ADBannerViewDelegate {

var AdBanner = ADBannerView()

override func viewDidLoad() {
    super.viewDidLoad()

        /* Ad Banner Settings */

        AdBanner = ADBannerView()
        AdBanner.frame = CGRectZero
        AdBanner.delegate = self
        self.AdBanner.frame = CGRectMake(0, self.view.frame.size.height-self.AdBanner.frame.size.height, self.AdBanner.frame.size.width, self.AdBanner.frame.size.height)
        AdBanner.backgroundColor = UIColor.clearColor()
        self.view.addSubview(AdBanner)

}

/* All iAd Functions */

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
/* whatever you need */
    return true
}

func bannerViewActionDidFinish(banner: ADBannerView!) {
/* whatever you need */
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    AdBanner.hidden = false
}


func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    NSLog("Error Loading Ad")
/* whatever you need */
    AdBanner.hidden = true
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
/* whatever you need */
}