How can you integrate Google Admob in a .NET MAUI app?
Asked Answered
T

1

6

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?

Transformation answered 12/4, 2023 at 17:33 Comment(1)
did you find a solution? I'm using the same Nuget but it doesn't work for iOSBrianabriand
E
1
  • 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.

Equimolecular answered 30/5, 2023 at 3:11 Comment(2)
Android works for this library but iOS has issues. Object null exception when using MobileAds.SharedInstance.Start(CompletionHandler);Serigraph
@Serigraph Same here. iOS issues galore.Phalanger

© 2022 - 2024 — McMap. All rights reserved.