Admob 奖励视频只会出现一次,然后必须重新启动应用
Posted
技术标签:
【中文标题】Admob 奖励视频只会出现一次,然后必须重新启动应用【英文标题】:Admob rewarded video will only appear once then the app must be restarted 【发布时间】:2017-04-30 20:04:36 【问题描述】:我已将 admob 奖励视频集成到我的应用中。
当应用程序启动时,我点击“观看视频”按钮,奖励视频播放正常。
但是,如果我“关闭视频”然后尝试再次“观看视频”它不起作用。
视频结束后,如果我再次尝试“观看视频”,它就不起作用了。
好像视频一旦打开过一次就不会再打开了。
所以在 SKScene 我有:
func videoAd()
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "loadAndShow3"), object: nil)
在视图控制器中:
func loadAndShow3()
GADRewardBasedVideoAd.sharedInstance().delegate = self
GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self)
func rewardBasedVideoAdDidReceive(_ rewardBasedVideoAd: GADRewardBasedVideoAd)
if GADRewardBasedVideoAd.sharedInstance().isReady
GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self)
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didRewardUserWith reward: GADAdReward)
let oldCoin = UserDefaults.standard.integer(forKey: "COINSCORE")
let newCoin = oldCoin + 20
UserDefaults.standard.set(newCoin, forKey: "COINSCORE")
UserDefaults.standard.synchronize()
if let view = self.view as! SKView?
if let scene3 = GameOverMenu(fileNamed: "Gameover")
scene3.viewController = self
scene3.scaleMode = .aspectFill
view.presentScene(scene3)
scene3.coinLabel.removeFromParent()
scene3.createCoinScore()
在我的委托中:
let request = GADRequest()
GADRewardBasedVideoAd.sharedInstance().load(request, withAdUnitID: "ca-app-pub-3940256099942544/1712485313")
【问题讨论】:
【参考方案1】:您需要为GADRewardBasedVideoAd
实现委托方法。
具体来说:
func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd)
print("Reward based video ad is closed.")
您应该在这里建立一个新的GADRewardBasedVideoAd
并请求一个新的广告。
【讨论】:
谢谢丹尼尔。我已经实现了该方法并将上面显示的委托中的代码放入其中,但是每当广告现在关闭时,它就会启动另一个广告而无需按下按钮【参考方案2】:已修复,不得不改组视图控制器中的一些代码并实现 Daniel 的回答
override func viewDidLoad()
super.viewDidLoad()
GADRewardBasedVideoAd.sharedInstance().delegate = self
let request = GADRequest()
GADRewardBasedVideoAd.sharedInstance().load(request, withAdUnitID: "ca-app-pub-3940256099942544/1712485313")
func loadAndShow3()
if GADRewardBasedVideoAd.sharedInstance().isReady
GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self)
func rewardBasedVideoAdDidReceive(_ rewardBasedVideoAd: GADRewardBasedVideoAd)
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didRewardUserWith reward: GADAdReward)
let oldCoin = UserDefaults.standard.integer(forKey: "COINSCORE")
let newCoin = oldCoin + 20
UserDefaults.standard.set(newCoin, forKey: "COINSCORE")
UserDefaults.standard.synchronize()
if let view = self.view as! SKView?
if let scene3 = GameOverMenu(fileNamed: "Gameover")
scene3.viewController = self
scene3.scaleMode = .aspectFill
view.presentScene(scene3)
scene3.coinLabel.removeFromParent()
scene3.createCoinScore()
func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd)
let request = GADRequest()
GADRewardBasedVideoAd.sharedInstance().load(request, withAdUnitID: "ca-app-pub-3940256099942544/1712485313")
【讨论】:
以上是关于Admob 奖励视频只会出现一次,然后必须重新启动应用的主要内容,如果未能解决你的问题,请参考以下文章