Swift Admob奖励Ad仅加载一次(对于新实现-迁移代码),并生成错误(“已使用.Ad对象”)
我遗留的Admob rewardedAd实现运行良好。今天我更新了新的实现,但它无法正常工作。除了Admob Swift代码有问题外(返回对象而不返回函数声明中的任何内容)…总之:Swift Admob奖励Ad仅加载一次(对于新实现-迁移代码),并生成错误(“已使用.Ad对象”),swift,admob,rewardedvideoad,Swift,Admob,Rewardedvideoad,我遗留的Admob rewardedAd实现运行良好。今天我更新了新的实现,但它无法正常工作。除了Admob Swift代码有问题外(返回对象而不返回函数声明中的任何内容)…总之: 我能够创建并加载初始的RewardedAd 当按下触发rewardedAd的按钮(通过通知)时,它会从调试器生成以下消息(“已呈现奖励广告”,紧接着是“未呈现奖励广告”和错误消息“加载失败:错误域=com.google.admob Code=18”演示错误:由于使用了ad对象,将不显示ad。“UserInfo={NS
var rewardedAd: GADRewardedAd?
override func viewDidLoad() {
...
createAndLoadRewardedAd()
...
{
/// creating the rewarded ad
func createAndLoadRewardedAd() {
rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313")
rewardedAd?.load(GADRequest()) { error in
if let error = error {
print("Loading failed: \(error)")
} else {
print("Loading Succeeded")
}
}
}
/// Lifecycle
/// Tells the delegate that the user earned a reward.
func rewardedAd(_ rewardedAd: GADRewardedAd, userDidEarn reward: GADAdReward) {
print("Reward received with currency: \(reward.type), amount \(reward.amount).")
}
/// Tells the delegate that the rewarded ad was presented.
func rewardedAdDidPresent(_ rewardedAd: GADRewardedAd) {
print("Rewarded ad presented.")
}
/// Tells the delegate that the rewarded ad was dismissed.
/// Load another ad upon dismissing the previous
func rewardedAdDidDismiss(_ rewardedAd: GADRewardedAd) {
print("RewardAd did dismiss")
createAndLoadRewardedAd()
}
/// Tells the delegate that the rewarded ad failed to present.
func rewardedAd(_ rewardedAd: GADRewardedAd, didFailToPresentWithError error: Error) {
print("Rewarded ad failed to present.")
print("Loading failed: \(error)")
}
/// Used by Notification Observer to present rewardedAd
@objc func startRewardVideoAd() {
if rewardedAd?.isReady == true {
rewardedAd?.present(fromRootViewController: self, delegate:self)
} else {
print("Reward based video not ready")
}
}