Test iAds won't load

为君一笑 提交于 2019-12-25 01:23:55

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/27995945/test-iads-wont-load

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!