Search code examples
iosswiftadbannerviewiad

iAd banner problems


The error and the problem:

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.

my implementation of the adView:

var adView = ADBannerView()
override func viewDidLoad() {
    super.viewDidLoad() 
    adView.frame = CGRectOffset(adView.frame, 0, self.view.bounds.height - adView.bounds.height)
    adView.sizeToFit()
    self.view .addSubview(adView)

    adView.alpha = 0.001
    adView.delegate = self

    }

i have looked on the internet and i found that i need to implement the "viewWillDisappear" and i did so:

my first try:

override func viewWillDisappear(animated: Bool) {

    adView.removeFromSuperview()
    adView.delegate = nil
}

and the second:

override func viewWillDisappear(animated: Bool) {
    for view in self.view.subviews {
        view.removeFromSuperview()
    }

    adView.removeFromSuperview()
    adView.delegate = nil
}

one more thing, it says that it will just be displayed once but i get the error every time i run the app on my phone


Solution

  • After some search i came to this solution :

        let adView = ADBannerView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
    adView.frame = CGRectOffset(adView.frame, 0, self.view.bounds.height - adView.bounds.height)
        adView.sizeToFit()
        adView.alpha = 0.001
        adView.delegate = self
        self.view .addSubview(adView)
    
        self.canDisplayBannerAds = true
        }
    
    
    override func viewWillDisappear(animated: Bool) {
        for view in self.view.subviews {
            view.removeFromSuperview()
        }
    
        adView.hidden = true
        adView.delegate = nil
    
        adView.removeFromSuperview()
    }
    

    apparently I missed to add the "self.canDisplayBannerAds = true" and that fixed the problem for now