Closed MarcosCostaDev closed 6 months ago
This issue has been fixed through a custom control.
public class AdvertisingControl : ContentView
{
public static readonly BindableProperty AdsIdentifierProperty = BindableProperty.Create(nameof(AdsIdentifier), typeof(string), typeof(AdvertisingControl), null);
public static readonly BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(BannerSize), typeof(AdvertisingControl), BannerSize.Banner);
public string AdsIdentifier
{
get => (string)GetValue(AdsIdentifierProperty);
set {
SetValue(AdIdentifierProperty, value);
}
}
public BannerSize Size
{
get => (BannerSize)GetValue(SizeProperty);
set => SetValue(SizeProperty, value);
}
public AdvertisingControl ()
{
}
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
if (string.IsNullOrWhiteSpace(AdsIdentifier)) return;
var adView = new MTAdView { AdsId = AdsIdentifier, AdSize = Size};
adView.LoadAd();
Content = adView;
}
}
and I add it in any page that I need to show Ad Banner
<controls:AdvertisingControl AdsIdentifier="ca-app-pub-3940256099942544/6300978111" />
I don't know if it's just me. But I have a routine that sets the AdId programmatically, and I am receiving this error
Java.Lang.IllegalStateException: 'The ad size and ad unit ID must be set before loadAd is called.'
this is the way I am setting the ads.
I am using the MVVM with the Maui Toolkit
My MauiProgram
This is some logs I am receiving
Version 1.0.2 was also tested in version 1.0.4 Project using net7.0-android