运行应用时,AdMob横幅广告未显示

时间:2016-09-25 13:58:40

标签: ios swift xcode admob

我认为我正确设置了横幅广告的代码,但是当我在模拟器或iPhone上运行应用程序时,没有出现。

@IBOutlet var BannerAD: GADBannerView!

@IBOutlet var ScoreLabel: UILabel!

var taps = Int(){
    didSet {
        if taps == 330 {
            print("You have reaches 5 taps !!")
        }
    }
}


override func viewDidLoad() {
    super.viewDidLoad()
    //BannerView
    let request = GADRequest()
    request.testDevices = [kGADSimulatorID]
    BannerAD.delegate = self
    BannerAD.adUnitID = "ca-app-pub-1469592343938512/3073825187"
    BannerAD.rootViewController = self
    BannerAD.loadRequest(request)

2 个答案:

答案 0 :(得分:0)

将此行添加到viewDidLoad(但在您发出广告请求之前):

BannerAd = GADBannerView(adSize: kGADAdSizeBanner)

执行此操作时,可能需要设置广告框架,如下所示:

BannerAd.frame = CGRect(x: 0, y: 0, width: 320, height: 50)

答案 1 :(得分:0)

尝试实施GADBannerViewDelegate委托方法,以检查应用是否正在接收广告:

func adViewDidReceiveAd(_ bannerView: GADBannerView!) {
   print("ad received")
}

func adView(_ bannerView: GADBannerView!, didFailToReceiveAdWithError error: GADRequestError!) {
   print("fail to receive ad with error: \(error.localizedDescription)")
}