snksnk
snksnk

Reputation: 1595

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)
}
}

Upvotes: 2

Views: 930

Answers (2)

snksnk
snksnk

Reputation: 1595

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

Upvotes: 5

Raja Kishan
Raja Kishan

Reputation: 18954

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())
    }
}

Upvotes: 4

Related Questions