本文介绍了adDidDismissFullScreenContent() 永远不会在版本 8 上被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GADRewardedAd,我的要求是在广告关闭时显示视图.在 API 版本 8 更新 adDidPresentFullScreenContent() 被调用,但 adDidDismissFullScreenContent() 方法从未被调用.

I am using GADRewardedAd and my requirement is when ads closed then it showing a view. On API version 8 update adDidPresentFullScreenContent() is called but the adDidDismissFullScreenContent() method are never called.

private var rewardedAdView: GADRewardedAd!
GADRewardedAd.load(withAdUnitID: UserDefaults.standard.string(forKey: Constants.ADMOB_KEY_AD_REWARDED) ?? "",
                            request: GADRequest(), completionHandler: { (ad, error) in
                              if let error = error {
                                print("Rewarded ad failed to load with error: \(error.localizedDescription)")
                                return
                              }
                              self.rewardedAdView = ad
                              self.rewardedAdView.fullScreenContentDelegate = self
                            }
private func showRewardedAds(){
        self.isAdEarnComplete = false
        if let ad = rewardedAdView {
              ad.present(fromRootViewController: self,
                       userDidEarnRewardHandler: {
                               showToast(viewContoler: self, message: "Your coupon is ready!")
                       }
              )
    }

extension HomeViewController: GADFullScreenContentDelegate{
    func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
        print("Rewarded ads present")
    }

    func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
        print("Rewarded ads dismiss")
    }


    func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
        printLog(tag: TAG, message:  "Error: \(error.localizedDescription)")
    }
}

推荐答案

import UIKit
import GoogleMobileAds
class ViewController: UIViewController, GADFullScreenContentDelegate  {
    @IBOutlet weak var btnRwdClick: UIButton!
    var rewadAd: GADRewardedAd?
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        GADRewardedAd.load(
            withAdUnitID: "ca-app-pub-3940256099942544/1712485313", request: GADRequest()
        ) { (ad, error) in
            if let error = error {
                print("Rewarded ad failed to load with error: \(error.localizedDescription)")
                return
            }
            print("Loading Succeeded")
            self.rewadAd = ad
            self.rewadAd?.fullScreenContentDelegate = self
        }
    }

    @IBAction func rewadAdTouched(_ sender: Any) {
        if let ad = rewadAd {
            ad.present(fromRootViewController: self) {
                let reward = ad.adReward
                print("Reward received with currency \(reward.amount), amount \(reward.amount.doubleValue)")

                // TODO: Reward the user.
            }
        } else {
            //Failed
        }
    }
    func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
        print("Rewarded ad presented.")
    }

    func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
        print("Rewarded ad dismissed.")
    }

    func ad(
        _ ad: GADFullScreenPresentingAd,
        didFailToPresentFullScreenContentWithError error: Error
    ) {
        print("Rewarded ad failed to present with error: \(error.localizedDescription).")

    }

}

这篇关于adDidDismissFullScreenContent() 永远不会在版本 8 上被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 01:32