iAd is NOT loading with Swift

108 views Asked by At

I have the following code.

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

self.canDisplayBannerAds = true
    self.theTopAdBannerView?.hidden = false


    func loadAds(){

        theTopAdBannerView.delegate = self
        theTopAdBannerView.hidden = false
        view.addSubview(theTopAdBannerView)
    }

    loadAds()
}

I made sure I linked up theTopAdBannerView outlet to the AdBanner. When I open it, it just shows a blank white space on where I placed the AdBanner in the storyboard. Why aren't my ads showing up?

I get this error

Error Domain=ADErrorDomain Code=5 "The operation couldn’t be completed. Banner view is visible but does not have content" UserInfo=0x7f9e2b5e3640 {ADInternalErrorCode=5, NSLocalizedFailureReason=Banner view is visible but does not have content, ADInternalErrorDomain=ADErrorDomain}
2

There are 2 answers

0
Amit Kalra On BEST ANSWER

Apparently my ad wasn't loading. All of a sudden it loads fine now. The code is fine.

3
Nilesh Patel On

Below code worked for me, Hope it works for you as well.

func displayAd(){
  adBannerView = ADBannerView(frame: CGRect.zeroRect)
  adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
  adBannerView.delegate = self
  adBannerView.hidden = true
  view.addSubview(adBannerView)
}

Calling loadAds from viewDidLoad method.

In didLoadAd method made adBannerView.hidden = false

AND

In didFailToReceiveAdWithError made adBannerView.hidden = true