需要帮助在Spritekit iOS游戏中集成插页式广告

时间:2016-10-20 05:11:26

标签: ios swift xcode admob

我正在使用Xcode和SpriteKit制作游戏,我正在使用admob整合广告,并且所有代码都适用于横幅广告,并且能够让插页式广告同时发挥作用。我的问题是告诉游戏何时显示插页式广告。广告在GameViewController中,但我需要从GameScene.swift调用showAd()方法。如何从GameScene中的GameViewController调用函数。感谢任何帮助,谢谢,Zach。

1 个答案:

答案 0 :(得分:2)

function isInt(val) { return val + 0 === val; } 中,在GameViewController中设置通知观察者,如下所示:

viewWillLayoutSubviews

然后在你的GameScene中,当你想要运行override func viewWillLayoutSubviews() { NotificationCenter.default.addObserver(self, selector: #selector(self.showAd), name: NSNotification.Name(rawValue: "showAd"), object: nil) } 中的函数时调用它:

GameViewController

请记住,您需要在NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showAd"), object: nil) 内调用一个函数。 GameViewController只是您希望在showAd内运行的任何功能的占位符。

希望这有帮助!

相关问题