iAd 未加载 Swift

iAd is NOT loading with Swift

我有以下代码。

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()
}

我确保已将 TopAdBannerView 插座链接到 AdBanner。当我打开它时,它只在故事板中放置 AdBanner 的位置显示空白 space。为什么我的广告没有展示?

我收到这个错误

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}

下面的代码对我有用,希望对你也有用。

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)
}

viewDidLoad 方法调用 loadAds。

didLoadAd方法中制作adBannerView.hidden = false

didFailToReceiveAdWithError取得adBannerView.hidden = true

显然我的广告没有加载。突然间它现在加载正常了。代码没问题。