Im trying to implement native ads but the adLoader Delegates don't get called. The more interesting is that the delegate for some reason becomes prints nil. No errors printed not receive. Any advice is greatly appreciated.
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)
}
}
Found the problem.. For anyone in the future who has the same issue, the correct delegate is GADNativeAdLoaderDelegate and not GADNativeAdDelegate nor GADAdLoaderDelegate
Currently, your GADAdLoader object scope is within the getAd function. Once the function is over all things release.
Try to set GADAdLoader object reference within the class.
class ViewController: UIViewController {
var adLoader: GADAdLoader!
func getAd(){
self.adLoader = GADAdLoader(adUnitID: adUnitID, rootViewController: self, adTypes: [.native], options: [options])
adLoader.delegate = self
print(adLoader.delegate)
adLoader.load(GADRequest())
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With