ViewDelegate不会在Swift中触发adViewDid

ViewDelegate不会在Swift中触发adViewDid

本文介绍了GADBannerViewDelegate不会在Swift中触发adViewDidReceiveAd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一个名为工具的类中使用GADBannerView。但是adViewDidReceiveAd委托方法不会在Tools类中触发。我该怎么办?

I use GADBannerView in another class that named Tools. But adViewDidReceiveAd delegate method doesn't fire in Tools class. What can I do?

class Tools: NSObject, GADBannerViewDelegate {

    var viewController: UIViewController!

    func showAds(viewController: UIViewController) -> Void {

        self.viewController = viewController

        let request: GADRequest = GADRequest()
        request.testDevices = [kGADSimulatorID]

        let bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)
        bannerView.delegate = self
        bannerView.rootViewController = viewController
        bannerView.adUnitID = "ca-app-pub-xxx-xxx"
        bannerView.loadRequest(request)

    }

    func adViewDidReceiveAd(bannerView: GADBannerView!) {
        print("adViewDidReceiveAd");
        viewController.view.addSubview(bannerView)
    }
}

然后,我在ViewController中调用了工具

And, I called Tools in ViewController

override func viewDidLoad() {
    super.viewDidLoad()
    Tools().showAds(self);
}


推荐答案

然后我遇到了同样的问题我替换了

I had the same problem then I replaced the

private func adViewDidReceiveAd(_ bannerView: DFPBannerView) {}

with

func adViewDidReceiveAd(_ bannerView: GADBannerView) {}

然后解决了问题。我希望它也对您有帮助。

then problem is solved. I hope it helps you, too.

这篇关于GADBannerViewDelegate不会在Swift中触发adViewDidReceiveAd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 21:05