我正在用AdMob制作一个应用程序,问题是:这个应用程序成功地加载了广告,但是当试图呈现它时,似乎广告还没有加载。我已经按照谷歌AdMob上的指南。。。
以下是我的viewDidLoad()
interstitial = GADInterstitial(adUnitID: "ca-app-pub-45863574112xxxxxxxxxx/xxxxxxx")
let request = GADRequest()
interstitial.load(request)
这就是我在点击按钮时所说的:
if self.interstitial.isReady {
self.interstitial.present(fromRootViewController: self)
} else {
let alert = UIAlertController(title: "Couldn't load ad", message: "There was a problem while loading the ad... Still, thank you for wanting to support me :)", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok...", style: .cancel, handler: nil))
self.present(alert, animated: true)
}
好吧,我收到警报。。。你能告诉我为什么吗?
最佳答案
您可以告诉自己原因:)通过实现delegate方法https://developers.google.com/admob/ios/api/reference/Protocols/GADInterstitialDelegate
特别是optional func interstitial(_ ad: GADInterstitial!, didFailToReceiveAdWithError error: Any!)