gpt4 book ai didi

ios - Swift(SpriteKit)/AdMob - 插页式广告请求错误

转载 作者:行者123 更新时间:2023-11-30 11:48:56 24 4
gpt4 key购买 nike

在 AdMob 中,当我调用插页式广告时,日志会显示“请求错误:不会发送请求,因为已使用插页式对象。”

我该如何解决这个问题?

我的代码是:

//
// GameViewController.swift//
//


class GameViewController: UIViewController, GADInterstitialDelegate {

var interstitial: GADInterstitial!

override func viewDidLoad() {
super.viewDidLoad()

PlayGame()

interstitial = createAndLoadInterstitial()
interstitial.delegate = self

}

func PlayGame() {
if let view = self.view as! SKView? {
if let scene = MainMenu(fileNamed: "MainMenu") {
scene.scaleMode = .aspectFit
view.presentScene(scene)
}

view.ignoresSiblingOrder = false
view.showsFPS = false
view.showsNodeCount = false
}
}


override func viewWillLayoutSubviews() {
NotificationCenter.default.addObserver(self, selector: #selector(self.interstitialAdShow), name: NSNotification.Name(rawValue: "showGecisAd"), object: nil)
}


func createAndLoadInterstitial() -> GADInterstitial {
var interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
interstitial.delegate = self
var request = GADRequest()
request.testDevices = [kGADSimulatorID]
interstitial.load(request)
return interstitial
}

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


@objc func interstitialAdShow() {

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

最佳答案

我认为您的广告因广告错误而未展示,因此您再次使用同一实例!如果这是真的,那么这将起作用:

func interstitial(_ ad: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError {
// you should add a delay here because if the user’s internet connection is disconnected you’ll get this called too many times too frequently
interstitial = createAndLoadInterstitial()
}

但是,如果您确实看到了广告,则说明您的委托(delegate)方法 interstitialDidDismissScreen 没有被调用,只需检查原因即可

祝你好运

关于ios - Swift(SpriteKit)/AdMob - 插页式广告请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48528019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com