Admob 插页式广告不会展示 iOS

Admobs interstitial ad won't show iOS

因此,我按照 Admob 网站上的代码让插页式广告正常工作,然后最近我更新了 pods 并使用它更新了 GoogleAdMob SDK。

现在,当我的插页式广告应该出现时,没有任何反应,并且在控制台中出现此错误:

[进程暂停] 0x110adfbd0 - ProcessAssertion::processAssertionWasInvalidated()

这是我的代码:

extension FirstViewController: GADInterstitialDelegate {
    
    func showInterstitialAd() {
        if interstitial.isReady {
            interstitial.present(fromRootViewController: self)
          } else {
            print("Ad wasn't ready")
          }
    }
    
    func createAndLoadInterstitial() -> GADInterstitial {
        var interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
        interstitial.delegate = self
        interstitial.load(GADRequest())
        return interstitial
    }

    func interstitialDidDismissScreen(_ ad: GADInterstitial) {
        interstitial = createAndLoadInterstitial()
    }
    
}

在 viewDidLoad 中我调用:

func setUpInterstitial() {
        
        interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
        interstitial.delegate = self
        
        let request = GADRequest()
        interstitial.load(request)
    }

并且在 ViewWillAppear

if InterstitialAd.counter >= 3 { self.showInterstitialAd(); InterstitialAd.counter = 0}

本意逻辑是用户每浏览3次页面,即FirstViewController,一个插屏广告展示。

提前谢谢你:)

您可以像下面这样更新您的代码:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    if InterstitialAd.counter >= 3 {
        self.showInterstitialAd(); 
        InterstitialAd.counter = 0
    }
}

从 viewWillAppear 中删除您的代码。