我正在尝试奖励用户使用AdMob观看视频.虽然我找不到关于这个主题的任何教程,但我在文档中找到了这两个类:
我已使用以下View Controller代码设置了GADRewardBasedVideoAd的显示:
class MarketController: UIViewController, GADRewardBasedVideoAdDelegate {
override func viewDidLoad() {
super.viewDidLoad()
GADRewardBasedVideoAd.sharedInstance().delegate = self
let request = GADRequest()
// Requests test ads on test devices.
request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
GADRewardBasedVideoAd.sharedInstance().loadRequest(request, withAdUnitID: "ca-app-pub-3940256099942544/4411468910")
}
// MARK: Daily Reward Button Delegate
@IBAction func playVideoClicked() {
if GADRewardBasedVideoAd.sharedInstance().ready {
GADRewardBasedVideoAd.sharedInstance().presentFromRootViewController(self)
}
}
// MARK: GADRewardBasedVideoAdDelegate
func rewardBasedVideoAdDidStartPlaying(rewardBasedVideoAd: GADRewardBasedVideoAd!) {
MediaPlayer.pauseBackgroundMusic()
print("Reward Video: Started")
}
func rewardBasedVideoAdDidClose(rewardBasedVideoAd: GADRewardBasedVideoAd!) {
MediaPlayer.startBackgroundMusic()
requestLoadAd()
print("Reward Video: Complete")
}
func rewardBasedVideoAdWillLeaveApplication(rewardBasedVideoAd: GADRewardBasedVideoAd!) {
requestLoadAd()
print("Reward Video: Will leave application")
}
}
当我按下按钮触发“playVideoClicked”功能中的代码时,我只看到常规测试插页式广告(没有视频),并且永远不会调用“rewardBasedVideoDidStartPlaying”函数.当我关闭插页式广告时,会调用“rewardBasedVideoAdDidClose”函数.这是否意味着我做错了什么,或者AdMob是不是只显示测试视频?
另外,如何在AdMob开发者控制台中将此广告配置为奖励视频?
最佳答案 将request.testDevices = [“2077ef9a63d2b398840261c8221a0c9b”]更改为request.testDevices = [kGADSimulatorID],它应该正常工作.