【问题标题】:Swift(SpriteKit) / AdMob - Interstitial Ads Request ErrorSwift(SpriteKit) / AdMob - 插页式广告请求错误
【发布时间】:2018-01-30 18:18:09
【问题描述】:

在 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")
        }
    }

【问题讨论】:

  • 你的代码看起来不错,你能展示一下使用那个类的代码吗? (显然是你的 ViewController)
  • İn 我的 GameScene 如果玩家死亡,我使用以下代码:NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showGecisAd"), object: nil)
  • 也许这可以帮助你:stackoverflow.com/questions/24353456/…

标签: ios swift xcode admob interstitial


【解决方案1】:

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

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()
}

但是如果您确实看到了您的广告,那么您的委托方法 interstitialDidDismissScreen 没有被调用,请检查原因

祝你好运

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多