如何在应用启动后加载插页式广告

时间:2016-04-02 18:39:10

标签: ios swift interstitial

这是我的代码。它不起作用。建设与发展运行成功但没有插页式广告加载。我该怎么办?

class ViewController: UIViewController {

    var interstitial: GADInterstitial!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")

        let request = GADRequest()
        // Requests test ads on test devices.
        request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
        self.interstitial.loadRequest(request)
        load()

    }
    func load() {
        if self.interstitial.isReady {
            self.interstitial.presentFromRootViewController(self)
        }

    }


}

2 个答案:

答案 0 :(得分:0)

在ViewDidAppear事件中尝试一下,我记得我之前遇到过这个问题

答案 1 :(得分:0)

试试此代码

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    if self.interstitial.isReady {
        self.interstitial.presentFromRootViewController(self)
    }
}