Search code examples
objective-cexceptionxamarin.iosappodeal

Xamarin.iOS. Appodeal. NSInvalidArgumentException Reason: -[APDImage imageUrl]


Xamarin.iOS. Appodeal. Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[APDImage imageUrl]: unrecognized selector sent to instance 0x280002420

enter image description here

class NativeAdDelegate : APDNativeAdLoaderDelegate
{
    NativeAdView _nativeAdView;

    public NativeAdDelegate(NativeAdView nativeAdView) =>
        _nativeAdView = nativeAdView;

    public override void NativeAdLoader(APDNativeAdLoader loader, NSError error) =>
        Console.WriteLine("APDNativeAd DidFailToLoadWithError");

    public override void NativeAdLoader(APDNativeAdLoader loader, NSArray nativeAds) =>
        _nativeAdView.DidLoad(nativeAds.GetItem<APDNativeAd>(0));
}

In

nativeAds.GetItem(0)

I have title and descriptionText, but I haven't images. I get exception in nativeAds.GetItem(0).IconImage.ImageUrl.


Solution

  • APDImage * mainImage - Bitmap of an image. An ad object contains both icon and image. It’s mandatory to use at least one of these elements.

    Deprecated method.

    For more details you can refer here.

    public override void NativeAdLoader(APDNativeAdLoader loader, NSArray nativeAds)
    {
        _nativeAdView.DidLoad(nativeAds.GetItem<APDNativeAd>(0));
    }
    
    public void DidLoad(APDNativeAd nativeAd)
    {
         this.nativeAd = nativeAd;
         UIView view = new UIView();
         view.Frame = new System.Drawing.Rectangle(10, 30, 200, 200);
         view.BackgroundColor = UIColor.FromRGB(96, 36, 36);
         View.AddSubview(view);
         this.nativeAd.AttachToView(view, UIApplication.SharedApplication.Windows[0].RootViewController);
         this.myMediaView.SetNativeAd(this.nativeAd, this);
         View.AddSubview(this.myMediaView); 
    }