首页 文章

Admob:插页式广告从未准备好

提问于
浏览
0

我在swift中为iOS编写了我的第一个Admob代码 . 我从来没有加载测试广告 . 这是我在GameViewController.swift中非常简单的代码 .

var interstitial: GADInterstitial!

override func viewDidLoad() {
    super.viewDidLoad()

    interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
    let request = GADRequest()
    request.testDevices = [kGADSimulatorID, "542C7C80-AEC2-464F-B673-D005953E9307"]
    interstitial.load(request)

    sleep(10)

    if interstitial.isReady{
      interstitial.present(fromRootViewController: self)
    }
    else{
      print("Ad not ready")
    }

能给我一个暗示会很高兴 .

1 回答

  • 0

    不要使用 sleep(x) !无论如何,使用 delegates 会在广告准备好呈现时通知您 . 像这样:

    // MARK: - GADInterstitialDelegate
    
    extension ViewController: GADInterstitialDelegate {
        func interstitialDidReceiveAd(_ ad: GADInterstitial) {
            ad.present(fromRootViewController: self)
        }
    }
    

    不要忘记设置 interstitial 实例的委托:

    self.interstitial.delegate = self

相关问题