Search code examples
iosiphoneswiftiad

Test iAds won't load


I've been scratching my head about this for a couple of days. I can't get iAds to show up in the simulator (or real hardware).

  1. I filled out all the contract information on iTunes Connect
  2. Created a development provisioning profile for the app
  3. Linked the iAd framework and imported it at the top of the ViewController's swift file
  4. Made the ViewController a subclass of ADBannerViewDelegate
  5. implemented 3 methods for the delegate (see below)

I can't figure out why the test ads aren't loading. Has anybody else had this problem? As I understand it you no longer have to register each app individually for iAds through iTunes Connect anymore.

I'll include my code below for reference, though I have a suspicion that the problem is somewhere in the setup.

import UIKit
import iAd

class AdViewController: UIViewController, ADBannerViewDelegate {

var bannerView = ADBannerView()

override func viewDidLoad() {
    super.viewDidLoad()

    self.canDisplayBannerAds = true

    bannerView.frame = CGRectMake(0, self.view.frame.height-50, self.view.frame.width, 50)
    view.addSubview(bannerView)

    bannerView.delegate = self
    bannerView.hidden = true

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    self.bannerView.hidden = false
    println("bannerView unhidden")
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    bannerView.hidden = true
    println("bannerView hidden")
}

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

Edit: This morning I tried downloading and running some iAd demos from gitHub just to see if I could get them to work, but to no avail. I assume the code is correct, so something must be wrong elsewhere. https://github.com/sarchak/iAds


Solution

  • it is not recommend to manually set the size of an ad view.
    use init() method and then adjust the frame doesn't make any sense

    you should initialize your banner view like this: let bannerView = ADBannerView(adType:ADAdType.Banner) and then immediately set its delegate and add it to the root view