AdMob插页式广告错误"请求错误:无广告显示"

时间:2015-09-28 12:27:48

标签: ios swift admob

我正在使用Swift2和Xcode7开发iOS应用程序。我尝试实施AdMob,但它没有显示我的插页式广告。

override func viewDidLoad() {
    super.viewDidLoad()

    _interstitial = createAndLoadInterstitial()
}

func createAndLoadInterstitial()->GADInterstitial {
    let interstitial = GADInterstitial(adUnitID: "interstitial_ID")
    let gadRequest:GADRequest = GADRequest()
    gadRequest.testDevices = ["test device id"]
    interstitial.delegate = self
    interstitial?.loadRequest(gadRequest)

    return interstitial!
}

func interstitialDidReceiveAd(ad: GADInterstitial!) {
    _interstitial?.presentFromRootViewController(self)
}

func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
    print(error.localizedDescription)
}

func interstitialDidDismissScreen(ad: GADInterstitial!) {
    _interstitial = createAndLoadInterstitial()
}

我收到此错误:

  

请求错误:无广告显示。

enter image description here

2 个答案:

答案 0 :(得分:9)

Request Error: No ad to show.

表示您的请求已成功,但Admob目前无法为您的设备展示广告。确保始终展示广告的最佳方法是使用中介,以便将未实现的请求传递到其他广告网络。 Admob提供了良好的机制来实现这一目标。

答案 1 :(得分:3)

您应该有两个广告单元ID。一个适用于GADBannerView,另一个适用于GADInterstitial。确保AdMob为您的插页式广告提供的广告单元ID 完全与他们给您的相同。更新到latest AdMob SDK,目前为7.5.0。还可以考虑按特定时间间隔或在用户完成所需操作后调用presentFromRootViewController(self)。您现在设置它的方式将继续一个接一个地展示插页式广告,因为您每次解散时都会发送新的插页式广告请求,然后在收到广告后立即显示插页式广告。

import UIKit
import GoogleMobileAds

class ViewController: UIViewController, GADInterstitialDelegate {

    var myInterstitial : GADInterstitial?

    override func viewDidLoad() {
        super.viewDidLoad()
        myInterstitial = createAndLoadInterstitial()
    }

    func createAndLoadInterstitial()->GADInterstitial {
        let interstitial = GADInterstitial(adUnitID: "Your Ad Unit ID")
        interstitial.delegate = self
        interstitial?.loadRequest(GADRequest())
        return interstitial
    }

    @IBAction func someButton(sender: AnyObject) {
        myInterstitial?.presentFromRootViewController(self)
    }

    func interstitialDidReceiveAd(ad: GADInterstitial!) {
        print("interstitialDidReceiveAd")
    }

    func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
        print(error.localizedDescription)
    }

    func interstitialDidDismissScreen(ad: GADInterstitial!) {
        print("interstitialDidDismissScreen")
        myInterstitial = createAndLoadInterstitial()
    }