4

I have a MAUI Blazor App on android and I want to use Google ads on it. So far, I couldn't find a way to do it.

Some solutions I've found involved using MauiMTAdmob plugin but it didn't work for me. I was getting a lot of errors and I couldn't even uninstall the nuget package from the project afterwards.

Did anyone manage to use Admob with the latest version of MAUI?

Is there any official suport for admob on MAUI? Will there be in the future?

F Andrei
  • 668
  • 2
  • 9
  • 24

1 Answers1

2
  • Search for "maui admob" and add Nuget package Follow the directions presented in the readme

  • In MauiProgram add .UseMauiMTAdmob() to the builder

  • You'll need to override Android MainApplication to add the OnCreate Method and override the iOS AppDelegate to add FinishedLaunching In both override methods you need to add the appropriate init code (see below)

  • Android manifest and iOS plist need to have the appid added

  • In App.xaml.cs App() method add

    CrossMauiMTAdmob.Current.UserPersonalizedAds = true; CrossMauiMTAdmob.Current.ComplyWithFamilyPolicies = true; CrossMauiMTAdmob.Current.UseRestrictedDataProcessing = true; CrossMauiMTAdmob.Current.AdsId = testAdUnitId;

Android init code

public override void OnCreate()
    {
        base.OnCreate();
        MobileAds.Initialize(this);
    }

IOS init code

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
    MobileAds.SharedInstance.Start(CompletionHandler);

    return base.FinishedLaunching(application, launchOptions);
}

private void CompletionHandler(InitializationStatus status) { }

I haven't figured out how to make the ad load on only one view or a razor page. it has to be loaded using xaml.

technified
  • 353
  • 1
  • 2
  • 15