SKScene中的AdMob奖励视频

编程入门 行业动态 更新时间:2024-10-16 02:25:29
本文介绍了SKScene中的AdMob奖励视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正尝试在我的 sprite kit 游戏中制作一款奖励视频广告。我想在我的 GameScene.swift 类中添加奖励视频,但是问题是这不是 ViewController 而是 SKScene 。

I'm trying to create a rewarded video ad in my sprite kit game. I want to add the rewarded video in my GameScene.swift class but the problem is that this isn't a ViewController but a SKScene.

这不起作用,因为我的 GameScene.swift 不是 ViewController :

This doesn't work because my GameScene.swift isn't a ViewController:

ad.present(fromRootViewController: self)

我尝试了很多事情,但没有任何效果。有谁可以帮助我吗? 谢谢!

I've tried many things but nothing worked. Can someone help me please? Thanks!

(我想在玩家死亡时显示此奖励广告。)

(I want to display this rewarded ad when the player dies.)

推荐答案

在您的 GameViewController 中,在 viewWillLayoutSubviews 中设置观察器:

In your GameViewController, setup the observer in viewWillLayoutSubviews:

override func viewWillLayoutSubviews() { NotificationCenter.default.addObserver(self, selector: #selector(self.startVideoAd), name: NSNotification.Name(rawValue: "showVideoRewardAd"), object: nil) } func startVideoAd() { // Do something - play video ad }

在这种情况下,无论何时调用此通知后,将运行 GameViewController 中名为 startVideoAd 的函数。显然,您希望将名称更改为要运行的函数的名称。

In this case, whenever this notification is called, the function inside GameViewController named startVideoAd will be run. Obviously you would want to change the name to the name of your function that you want to be run.

然后,在您的 GameScene 中,要发送通知,无论何时何地,您都可以运行此通知 GameViewController 内的函数:

Then, in your GameScene, to send the notification, you would run this wherever/whenever you want to run the function inside GameViewController:

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

希望这会有所帮助!

Hope this helps!

更多推荐

SKScene中的AdMob奖励视频

本文发布于:2023-11-30 16:47:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650753.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频   SKScene   AdMob

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!