iAd不会加载测试广告

时间:2015-03-04 01:16:36

标签: ios swift sprite-kit iad

iAd根本不会加载测试广告,这让我感到疯狂。它只显示一个白色的盒子,不做任何回调。这是我的全部代码:

import UIKit
import iAd

class ViewController: UIViewController, ADBannerViewDelegate {

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

    self.canDisplayBannerAds = true

    let adBanner = ADBannerView()
    adBanner.delegate = self
    self.view.addSubview(adBanner)

    self.view.backgroundColor = UIColor.blackColor()

}

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


}

1 个答案:

答案 0 :(得分:1)

class ViewController: UIViewController, ADBannerViewDelegate {
  var adBannerView : ADBannerView

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

      self.canDisplayBannerAds = true

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

  func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
      //handle fail issue
      bannerView.hidden = true
  }

  func bannerViewDidLoadAd(banner: ADBannerView!) {
      bannerView.hidden = false 
  }
}