0

I have this code on all my viewcontroller pages to control my AdBanner across multiple pages. 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. 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."

` 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
Hiren Dhamecha
  • 658
  • 5
  • 15
ElectricTiger
  • 111
  • 1
  • 9
  • So I feel like I fixed the issue but I have my doubts. I replaced all my code with 1 line 'self.canDisplayBannerAds = true' It seems to be the solution but I don't know how it reacts. It is hard to tell in the simulator if every page loads a new ad or if this is a shared iAd banner. Can anyone enlighten me? – ElectricTiger Feb 02 '16 at 06:16

1 Answers1

0

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
}
vien vu
  • 4,277
  • 2
  • 17
  • 30