我正在尝试实现原生广告,但没有调用 adLoader 委托(delegate)。更有趣的是,由于某种原因,委托(delegate)变成了打印 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)
}
}
最佳答案
发现问题.. 对于将来遇到相同问题的任何人,正确的委托(delegate)是 GADNativeAdLoaderDelegate 而不是 GADNativeAdDelegate 或 GADAdLoaderDelegate
https://stackoverflow.com/questions/69505222/