首页 > 解决方案 > GAD adLoader 代表没有被调用

问题描述

我正在尝试实施原生广告,但没有调用 adLoader 代表。更有趣的是,由于某种原因,delegate 变成了 prints nil。没有错误打印不接收。任何意见是极大的赞赏。

func getAd(){
let adLoader = GADAdLoader(adUnitID: adUnitID, rootViewController: self, adTypes: [.native], options: [options])
    adLoader.delegate = self
    print(adLoader.delegate)
    adLoader.load(GADRequest())
}
extension ViewController:GADNativeAdDelegate, GADAdLoaderDelegate{
func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADNativeAd) {
    print("did receive")
  // A native ad has loaded, and can be displayed.
}

func adLoaderDidFinishLoading(_ adLoader: GADAdLoader) {
    print("finish Loading")
    // The adLoader has finished loading ads, and a new request can be sent.
}


func adLoader(_ adLoader: GADAdLoader, didFailToReceiveAdWithError error: Error) {
  print(error)
}
}

标签: iosswiftdelegatesadmob

解决方案


发现了问题.. 对于将来遇到相同问题的任何人,正确的代表是 GADNativeAdLoaderDelegate 而不是 GADNativeAdDelegate 或 GADAdLoaderDelegate


推荐阅读