需要帮助在Spritekit iOS游戏中集成插页式广告
我正在使用Xcode和SpriteKit制作游戏,我正在使用admob整合广告,并使所有的代码都能够用于横幅广告,并且能够让插页式广告也能正常工作。 我的问题是告诉游戏何时显示插页式广告。 广告在GameViewController中,但我需要从GameScene.swift调用showAd()方法。我将如何去在GameScene中从GameViewController调用一个函数。 任何帮助表示赞赏,在此先感谢,扎克。
在你的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
只是你想在showAd
中运行的任何函数的占位符。
希望这有助于!