简体   繁体   English

ADBannerView问题

[英]ADBannerView Issues

I have this code on all my viewcontroller pages to control my AdBanner across multiple pages. 我对我所有的这些代码viewcontroller页来控制我的AdBanner多个页面。 It works correctly on the last version on my app but for some reason in this update I'm working on I don't think my app is calling either the bannerViewDidLoadAd or didFailToReceiveAdWithError functions. 它可以在我的应用程序的最新版本上正常工作,但是由于某些原因,我正在使用此更新,因此我认为我的应用程序没有调用bannerViewDidLoadAddidFailToReceiveAdWithError函数。 Also I am getting this error when I change pages a lot. 当我频繁地更改页面时,也会出现此错误。 ` `

"WARNING: More than 10 instances of ADBannerView or ADInterstitialView currently exist. This is a misuse of the iAd API, and ad performance will suffer as a result. This message is printed only once." “警告:当前存在10个以上的ADBannerView或ADInterstitialView实例。这是iAd API的滥用,因此广告性能会受到损害。此消息仅打印一次。”

` Is there something I am missing? `我有什么想念的吗? Thanks 谢谢

// Ad controller

var UIiAd: ADBannerView = ADBannerView()
var screenHeight = UIScreen.mainScreen().bounds.height
var adBannerHeight: CGFloat = 50
@IBOutlet var constOne: NSLayoutConstraint!

func appdelegate() -> AppDelegate {
    return UIApplication.sharedApplication().delegate as! AppDelegate
}

override func viewWillDisappear(animated: Bool) {
    UIiAd.delegate = nil
    UIiAd.removeFromSuperview()
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(1)
    UIiAd.alpha = 1
    adBannerHeight = 50
    UIView.commitAnimations()
    constOne.constant = 58
    print("ad loaded")
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(1)
    UIiAd.alpha = 0
    adBannerHeight = 0
    UIView.commitAnimations()
    constOne.constant = 8
    print("error")
}

override func viewWillAppear(animated: Bool) {
    UIiAd.delegate = self
    UIiAd = self.appdelegate().UIiAd
    UIiAd.frame = CGRectMake(0, screenHeight - adBannerHeight , 0, 0)
    self.view.addSubview(UIiAd)

}

// End of Ad Controller

Try to change this code: 尝试更改此代码:

override func viewWillDisappear(animated: Bool) {
    UIiAd.delegate = nil
    UIiAd.removeFromSuperview()
}

To: 至:

override func viewWillDisappear(animated: Bool) {
     UIiAd.removeFromSuperview()
     UIiAd.delegate = nil
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM