Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GAD adLoader Delegates not get Called

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)
}
}
like image 349
snksnk Avatar asked Dec 30 '25 16:12

snksnk


2 Answers

Found the problem.. For anyone in the future who has the same issue, the correct delegate is GADNativeAdLoaderDelegate and not GADNativeAdDelegate nor GADAdLoaderDelegate

like image 71
snksnk Avatar answered Jan 02 '26 05:01

snksnk


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())
    }
}
like image 29
Raja Kishan Avatar answered Jan 02 '26 04:01

Raja Kishan