[英]Admob: interstitial ad never ready
我正在為iOS迅速編寫我的第一個Admob代碼。 我從來沒有加載測試廣告。 這是我在GameViewController.swift中非常簡單的代碼。
var interstitial: GADInterstitial!
override func viewDidLoad() {
super.viewDidLoad()
interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
let request = GADRequest()
request.testDevices = [kGADSimulatorID, "542C7C80-AEC2-464F-B673-D005953E9307"]
interstitial.load(request)
sleep(10)
if interstitial.isReady{
interstitial.present(fromRootViewController: self)
}
else{
print("Ad not ready")
}
很高興給我一個提示。
不要使用sleep(x)
! 無論如何,只要准備好展示廣告,就可以使用delegates
來通知您。 像這樣:
// MARK: - GADInterstitialDelegate
extension ViewController: GADInterstitialDelegate {
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
ad.present(fromRootViewController: self)
}
}
不要忘記設置interstitial
實例的委托:
self.interstitial.delegate = self
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.