需要帮助在Spritekit iOS游戏中集成插页式广告 [英] Need Help Integrating Interstitial ads in Spritekit iOS Game

查看:106
本文介绍了需要帮助在Spritekit iOS游戏中集成插页式广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am making a game using Xcode and SpriteKit, I am integrating ads using admob and have all of the code working for the banner ads and have been able to get the interstitial ads to work as well. My problem is telling the game when to display the interstitial ad. The ad is in GameViewController but I need to call the showAd() method from GameScene.swift How would I go about calling a function from GameViewController in GameScene. Any help is appreciated, thanks in advance, Zach.

推荐答案

在你的 GameViewController ,在 viewWillLayoutSubviews 中设置通知观察者,如下所示:

In your GameViewController, setup a notification observer in viewWillLayoutSubviews like so:

override func viewWillLayoutSubviews() {

    NotificationCenter.default.addObserver(self, selector: #selector(self.showAd), name: NSNotification.Name(rawValue: "showAd"), object: nil)

}

然后在你的GameScene中,当你想要在<要运行code> GameViewController :

Then in your GameScene, call this when you want the function in GameViewController to be run:

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showAd"), object: nil)

请记住,你需要有一个在 GameViewController 中调用的函数。 showAd 只是您希望在 GameViewController 中运行的任何函数的占位符。

Keep in mind that you need to have a function to be called inside your GameViewController. showAd is just a placeholder for whatever function you want to be run inside your GameViewController.

希望这有帮助!

这篇关于需要帮助在Spritekit iOS游戏中集成插页式广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆