【问题标题】:Need Help Integrating Interstitial ads in Spritekit iOS Game需要帮助在 Spritekit iOS 游戏中集成插页式广告
【发布时间】:2016-10-21 04:45:08
【问题描述】:
我正在使用 Xcode 和 SpriteKit 制作游戏,我正在使用 admob 集成广告,并且所有代码都适用于横幅广告,并且能够让插页式广告也能正常工作。我的问题是告诉游戏何时显示插页式广告。广告在 GameViewController 中,但我需要从 GameScene.swift 调用 showAd() 方法我将如何从 GameScene 中的 GameViewController 调用函数。任何帮助表示赞赏,在此先感谢 Zach。
【问题讨论】:
标签:
ios
swift
xcode
admob
【解决方案1】:
在您的GameViewController 中,像这样在viewWillLayoutSubviews 中设置通知观察者:
override func viewWillLayoutSubviews() {
NotificationCenter.default.addObserver(self, selector: #selector(self.showAd), name: NSNotification.Name(rawValue: "showAd"), object: nil)
}
然后在您的 GameScene 中,当您想要运行 GameViewController 中的函数时调用它:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showAd"), object: nil)
请记住,您需要在 GameViewController 中调用一个函数。 showAd 只是一个占位符,表示您希望在 GameViewController 中运行的任何功能。
希望这会有所帮助!