如何呈现内SKScene谷歌的插页式广告

时间:2019-01-31 16:36:04

标签: swift sprite-kit interstitial

我无法在SKScene中展示插页式广告

我已经尝试从SKScene打电话给代表,但是没有运气。

我有3个文件,并调用。

  • MainVC->这基本上是GameViewController
  • MainSC-> MainVC呈现的SKScene文件
  • EasyScene->这是我无法展示的SKSCene 非页内广告

我可以从MainSC场景调用Google插页式广告,但不能从EasyScene调用它。我尝试了所有我能,但仍然没有运气。

我应该向EasyScene添加另一个委托以调用方法,还是应该从EasyScene调用该callMethod()。

谢谢。

  

MainVC

        import UIKit
        import SpriteKit
        import Firebase
        import StoreKit
        import GoogleMobileAds
        class MainVC: UIViewController, GADInterstitialDelegate, GADBannerViewDelegate, GameViewControllerDelegate{
    var interstitial: GADInterstitial!
         var bannerView: GADBannerView!
     override func viewDidLoad() {
            super.viewDidLoad()

            interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")

            interstitial = createAndLoadInterstitial()

            bannerView = GADBannerView(adSize: kGADAdSizeBanner)

            bannerView.delegate = self
            bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
            bannerView.rootViewController = self
            bannerView.load(GADRequest())
            addBannerViewToView(bannerView)
if let view = self.view as! SKView? {

            if let scene = SKScene(fileNamed: "MainSC") {

                let gameScene = scene as! MainSC

                gameScene.gameViewControllerDelegate = self

                gameScene.scaleMode = .aspectFill
                gameScene.size.width = width
                gameScene.size.height = height
                view.presentScene(gameScene)

            }

            view.ignoresSiblingOrder = true

            view.showsFPS = true
            view.showsNodeCount = true
            view.showsPhysics = false

        }
    }



    func callMethod() {


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

MainSC

import SpriteKit
import GameplayKit
import Firebase
import GoogleMobileAds

protocol GameViewControllerDelegate : class {
    func callMethod()
}

class MainSC: SKScene {
 weak var gameViewControllerDelegate : GameViewControllerDelegate?

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if node?.name == "easyButton" || node?.name == "easyTextim"{

                if let scene = SKScene(fileNamed: "EasyScene") {
                    let gameScene = scene as! EasyScene
                    gameScene.scaleMode = .aspectFill
                    gameScene.size.width = self.size.width
                    gameScene.size.height = self.size.height
                    self.view?.presentScene(gameScene)
                }


            }else if node?.name == "playButton"{

   gameViewControllerDelegate?.callMethod() //This guy here shows the Ads!

        }
}
  

EasyScene

如何从此处展示Google间隙广告?

0 个答案:

没有答案