3

I am trying to implement native ads in my Xamarin.ios application. My Adloader.delegate is always null and I cannot figure out how to solve this.

The application output says "Delegate does not conform to the required protocol, GADNativeAdLoaderDelegate".

The nuget package that I am using is: Xamarin.Google.ios.MobileAds

This is my code:

public ExploreController (IntPtr handle) : base (handle)
{
    adLoader = new AdLoader(
        "ca-app-pub-3940256099942544/3986624511",
        this,
        new AdLoaderAdType[] { AdLoaderAdType.Native },
        new AdLoaderOptions[] { new AdLoaderOptions() })
        { Delegate = new MyAdLoaderDelegate() };

    adLoader.LoadRequest(Request.GetDefaultRequest());
    
}



 public class MyAdLoaderDelegate : NSObject, IUnifiedNativeAdLoaderDelegate
 {

   public MyAdLoaderDelegate()
   {
   }

   public void DidReceiveUnifiedNativeAd(AdLoader adLoader, NativeAd nativeAd)
   {
       Debug.WriteLine("DidReceiveUnifiedNativeAd");
   }
   public void DidFailToReceiveAd(AdLoader adLoader, NSError error)
   {
      Debug.WriteLine("DidFailToReceiveAd");
      //base.DidFailToReceiveAd(adLoader, error);
   }

   public void DidFinishLoading(AdLoader adLoader)
   {
      Debug.WriteLine("DidFinishLoading");
      //base.DidFinishLoading(adLoader);
   }
}

UPDATE:

I changed IUnifiedNativeAdLoaderDelegate to UnifiedNativeAdLoaderDelegate and tried to override the methods, but stil same result:

public class MyAdLoaderDelegate : UnifiedNativeAdLoaderDelegate
{

    public override void DidFailToReceiveAd(AdLoader adLoader, NSError error)
    {
        base.DidFailToReceiveAd(adLoader, error);
    }

    public override void DidFinishLoading(AdLoader adLoader)
    {
        base.DidFinishLoading(adLoader);
    }

    public override void DidReceiveUnifiedNativeAd(AdLoader adLoader, NativeAd nativeAd)
    {
        throw new NotImplementedException();
    }
}
Malin
  • 97
  • 1
  • 8
  • https://stackoverflow.com/questions/69505222/gad-adloader-delegates-not-get-called – Jason Apr 25 '22 at 16:06
  • Can you explain how I should change my code? Because I don't understand. @Jason – Malin Apr 25 '22 at 16:12
  • I'm just pointing out that this problems sounds almost identical to yours. I'd guess that `IUnifiedNativeAdLoaderDelegate` is wrong, but I have no idea where that interface comes from. You haven't told us what nuget package that you're using to pull in the Admob API – Jason Apr 25 '22 at 16:16
  • I updated my question with the nuget package. Yes I thought so too, that the interface is wrong I mean, but it feels like I have tried everything, I am totally out of ideas. Can't seem to get it to work @Jason – Malin Apr 25 '22 at 16:31
  • What about replacing `IUnifiedNativeAdLoaderDelegate` with `GADNativeAdLoaderDelegate` ? – ColeX Apr 26 '22 at 01:59
  • It just says that the type or namespace doesn't exist :( @ColeX-MSFT – Malin Apr 26 '22 at 05:43
  • Replace `IUnifiedNativeAdLoaderDelegate` with `UnifiedNativeAdLoaderDelegate` and override the methods inside the class . – ColeX Apr 26 '22 at 05:58
  • I updated my question with the changes, unfortunately it still gives me the same message @ColeX-MSFT – Malin Apr 26 '22 at 06:12
  • Seems a part of the code is missing , consider raising the issue on github :https://github.com/xamarin/GoogleApisForiOSComponents/issues?q=is%3Aopen+is%3Aissue. – ColeX Apr 26 '22 at 09:29
  • 1
    Have you tried this nuget package instead? Xamarin.Firebase.iOS.AdMob – Saamer May 19 '22 at 12:48
  • Same here :( It is null. – T.Y. Kucuk Feb 18 '23 at 21:26

0 Answers0