Need Help Integrating Interstitial ads in Spritekit iOS Game

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

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.

回答1:

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)  } 

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) 

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.

Hopefully this helps!



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!