I need to implement Native Ads in Xamarin.Forms. But I did not find any examples on Xamarin.Forms.
Maybe someone has an example of using Native Ads on Xamarin.Forms and can share.
My example of what I was trying to do:
Android:
[assembly: Dependency(typeof(NativeAd))]
namespace Ads.Droid.Platform.Renderers.Ad
{
public class NativeAd : AdListener, INativeAd
{
Context context = Android.App.Application.Context;
NativeExpressAdView mAdView;
public void Show()
{
var videoOptions = new VideoOptions.Builder().SetStartMuted(false).Build();
var adOptions = new NativeAdOptions.Builder().SetVideoOptions(videoOptions).Build();
AdLoader adLoader = new AdLoader.Builder(context, "ca-app-pub-3940256099942544/2247696110").WithNativeAdOptions(adOptions).Build();
var request = new AdRequest.Builder();
foreach (var item in TestDevice.GetTestDevices())
request.AddTestDevice(item);
adLoader.LoadAd(request.Build());
}
}
}
or:
[assembly: Dependency(typeof(NativeAd))]
namespace Ads.Droid.Platform.Renderers.Ad
{
public class NativeAd : AdListener, INativeAd
{
NativeExpressAdView mAdView;
public void Show()
{
mAdView = new NativeExpressAdView(Android.App.Application.Context)
{
AdUnitId = "ca-app-pub-3940256099942544/2247696110",
AdSize = AdSize.MediumRectangle
};
var request = new AdRequest.Builder();
foreach (var item in TestDevice.GetTestDevices())
request.AddTestDevice(item);
mAdView.LoadAd(request.Build());
}
}
}
In iOS didn’t do it, but I also need an example.
Maybe something needs to be changed or completed.
Help me please.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…