Plugin.MauiMTAdmob 1.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Plugin.MauiMTAdmob --version 1.1.2
NuGet\Install-Package Plugin.MauiMTAdmob -Version 1.1.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plugin.MauiMTAdmob" Version="1.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plugin.MauiMTAdmob --version 1.1.2
#r "nuget: Plugin.MauiMTAdmob, 1.1.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plugin.MauiMTAdmob as a Cake Addin
#addin nuget:?package=Plugin.MauiMTAdmob&version=1.1.2

// Install Plugin.MauiMTAdmob as a Cake Tool
#tool nuget:?package=Plugin.MauiMTAdmob&version=1.1.2

Stop the WAR in Ukraine!

MAUIMtAdmob plugin for MAUI (Android & iOS)

With this Plugin you can add a Google Admob Ads inside your MAUI Projects with a single line!!! This plugin supports: Banners, Interstitial and Rewarded Videos

PLEASE READ

From version 1.1.0, I've added support for the consent required by Google for all the final users living in Europe. This support for UMP is only available in the licensed version of the plugin. Without the license, the plugin will continue to work as usual with all the other features normally available. This will allow me to continue supporting the development of the plugin. You can buy the license at https://hightouchinnovation.com/MMTAdmob If you are a charity or your app is used to support a good cause, contact me and I'll evaluate it to send you a free license.

CRYPTOGRAPHY

This plugin uses an cryptographic algorithm to handle the license.

Please, support me

If you prefer to not buy a license, if possible, please, support my work with few coffees or even better with a Membership! You can do it here: Buy Me A Coffee Your help allows me to continue to spend time on this project and continue to maintain and update it with new features and to be ready for the new Google SDK: Google SDK Migration.

Setup

This plugin supports:
  • Maui (Android and iOS)

DISCLAIMER OF LIABILITY

By using MAUIMtAdmob (the "Plugin"), you agree that:

  1. The Plugin is provided "as is" without any warranties or guarantees of any kind, either expressed or implied.
  2. I shall not be responsible or liable for any direct, indirect, incidental, special, or consequential damages arising out of the use or inability to use the Plugin.
  3. I do not warrant that the Plugin will meet your specific requirements or operate without interruption.

You acknowledge that the use of the Plugin is at your own risk. The author of the plugin disclaims all liability for any damage to your computer system or loss of data that results from the use of the Plugin.

This disclaimer of liability is a fundamental part of the agreement between you and the author of the plugin. You agree that the limitations and exclusions of liability set forth in this disclaimer are reasonable and fair.

If you do not agree to these terms, do not use the Plugin.

VERY IMPORTANT

If you encounter this build error: "Error: clang++ exited with code 1: Undefined symbols for architecture arm64: "OBJC_CLASS$_UMPConsentForm", referenced from: objc-class-ref in registrar.o"...

Install package Xamarin.Google.iOS.UserMessagingPlatform version 1.1.0.1 in you iOS project

How to use MauiMTAdmob

You can find a tutorial on my blog: https://www.xamarinexpert.it/admob-made-easy/ (Version for Xamarin, I'll update it with the new version for MAUI)

INITIALIZATION

in your CreateMauiApp() add this to your builder:

.UseMauiMTAdmob()

From your platform code, from version 1.1.0, you need to call:

CrossMauiMTAdmob.Current.Init(...);

EASY 😄

To add a banner in your project

To add a Banner on a page you have two options:

1) XAML
<controls:MTAdView x:Name="myAds"/>

remember to add this line in your XAML:

xmlns:controls="clr-namespace:Plugin.MauiMTAdmob.Controls;assembly=Plugin.MauiMTAdmob"

As you can have different Banner Ids for iOS and for Android, you could use the OnPlatform-Property like this:

<controls:MTAdView x:Name="myAds" AdsId="{OnPlatform Android='ca-app-pub-3940256099942544/6300978111', 
                                   iOS='ca-app-pub-3940256099942544/2934735716'}"/>

Or set it in App.xaml (similar to HeightRequest as explained below) for all banners in your app.

2) Code
MTAdView ads = new MTAdView();
Important

To test the banner during the development google uses two Banner Id, one for Android and the other for iOS. Use them then remember to replace them with your own IDs:

Android: ca-app-pub-3940256099942544/6300978111
iOS: ca-app-pub-3940256099942544/2934735716

Properties

For each AdView if you want, you can set these properties:

AdsId: To add the id of your ads

PersonalizedAds: You can set it to False if you want to use generic ads (for GDPR...) (It works only for Android Banners, for the others, you must ask for consent)

For GDPR it's better to rely on a custom consent instead or using the non personalized ads as I cannot guarantee it works. So it's better if you create a custom consent

Global Properties

AdsId: To add the id of your ads

PersonalizedAds: You can set it to False if you want to use generic ads (for GDPR...) (It works only for Android Banners, for the others, you must ask for consent) For GDPR it's better to rely on a custom consent instead or using the non personalized ads as I cannot guarantee it works. So it's better if you create a custom consent

TestDevices: You can add here the ID of your test devices

You can use Global Properties in this way:

CrossMauiMTAdmob.Current.UserPersonalizedAds = true;

Interstitial

You can show an interstitial with a single line of code:

CrossMauiMTAdmob.Current.ShowInterstitial();

To Load an interstitial you can use this line:

CrossMauiMTAdmob.Current.LoadInterstitial("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

To see if an interstitial is loaded:

CrossMauiMTAdmob.Current.IsInterstitialLoaded();

Rewarded

You can show a Rewarded video with a single line of code:

CrossMauiMTAdmob.Current.ShowRewarded();

To Load a Rewarded Video you can use this line:

CrossMauiMTAdmob.Current.LoadRewarded("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

To see if a rewarded is loaded:

CrossMauiMTAdmob.Current.IsRewardedLoaded();

Rewarded Interstitial

You can show a Rewarded video with a single line of code:

CrossMauiMTAdmob.Current.ShowRewardInterstitial();

To Load a Rewarded Video you can use this line:

CrossMauiMTAdmob.Current.LoadRewardInterstitial("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

To see if a rewarded interstitial is loaded:

CrossMauiMTAdmob.Current.IsRewardInterstitialLoaded();

Events for Banners

Just in case you need, the Banner ads offer 4 events:

AdsClicked		When a user clicks on the ads
AdsClosed		When the user closes the ads
AdsImpression	Called when an impression is recorded for an ad.
AdsOpened		When the ads is opened
AdsFailedToLoad Ads couldn't be loaded
AdsLoaded       Ads loaded

Events for Interstitials

the Interstitial ads offer 3 events:

OnInterstitialLoaded        When it's loaded
OnInterstitialOpened        When it's opened      
OnInterstitialClosed        When it's closed
OnInterstitialFailedToLoad
OnInterstitialFailedToShow

Events for Rewarded Videos

The Rewarded Videos offer 7 events:

OnRewardedLoaded                       
OnRewardedFailedToLoad        
OnRewardedFailedToShow
OnRewardedOpened
OnRewardedClosed
OnRewardedImpression

Events for Interstitials and Rewarded

The Rewarded Videos offer 7 events:

OnRewardedLoaded                       
OnRewardedFailedToLoad        
OnRewardedFailedToShow
OnRewardedOpened
OnRewardedClosed
OnRewardedImpression

Events for Rewarded and Rewarded interstitials

The Rewarded Videos offer 7 events:

OnUserEarnedReward

Important

Remember to include the MTAdmob library with this code (usually it's added automatically):

using Plugin.MauiMTAdmob;

Important for Android

If you are using the unlicensed version, before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.initialize() with your AdMob App ID. This needs to be done only once, ideally at app launch. For example:

 protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            MobileAds.Initialize(this);
        }

If you are using the licensed version, the plugin will initialize it for you if and when the consent has been obtained (if required).

Remember to add this to your AppManifest:


<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID"
           android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
<meta-data android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT" android:value="true"/>

If your Ads are not displayed on your Android Emulator, make sure your Emulator has Google Play Store API installed, otherwise you'll find this message in your Debugger Console:

[GooglePlayServicesUtil] Google Play Store is missing.

If it's still not showing ads after adding Play Store, open Google Play Store on your emulator. There might be some config work to be done by Play Store, e.g. login with your google account, so just start it and make sure it's working fine on your emulator.

IMPORTANT FOR IOS:

If you are using the unlicensed version, before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.SharedInstance.Start with your AdMob App ID. This needs to be done only once, ideally at app launch. For example:

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            MobileAds.SharedInstance.Start(CompletionHandler);   <--
            return base.FinishedLaunching(application, launchOptions);
        }

        private void CompletionHandler(InitializationStatus status) { }   <--

If you are using the licensed version, the plugin will initialize it for you if and when the consent has been obtained (if required).

Edit your info.plist adding these Keys:

  <key>GADApplicationIdentifier</key>
  <string>ca-app-pub-3940256099942544~1458002511</string> <- This is a test key, replace it with your APPID
  <key>GADIsAdManagerApp</key>
  <true/>
  <key>GADDelayAppMeasurementInit</key>
  <true/>

If you are builing your app for iOS on Windows without using your Mac, then MobileAds.SharedInstance will be null and the ads will not work.

You have to build the app using your Mac to use Admob on iOS!

That's it. Cannot be easier than that 😃

LINKS To buy the license visit https://hightouchinnovation.com/MMTAdmob Available on Nuget: https://www.nuget.org/packages/Plugin.MauiMTAdmob/ Tutorial: https://www.xamarinexpert.it/admob-made-easy/ (Version for Xamarin. I'll update it with the new version for MAUI) Guide: https://hightouchinnovation.com/MMTAdmobGuide To report any issue: https://github.com/marcojak/MauiMTAdmob/issues

Product Compatible and additional computed target framework versions.
.NET net8.0-android34.0 is compatible.  net8.0-ios17.2 is compatible.  net8.0-maccatalyst17.2 is compatible.  net8.0-windows10.0.19041 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Plugin.MauiMTAdmob:

Package Downloads
AnchorAppsIT.MAUI.Controls

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Plugin.MauiMTAdmob:

Repository Stars
lswiderski/mi-scale-exporter
Mobile App to export data from Mi Body Composition Scale and upload it to Garmin Connect Cloud
Version Downloads Last updated
1.4.2 343 4/12/2024
1.4.1 499 3/19/2024
1.4.0 163 3/18/2024
1.3.3 230 3/14/2024
1.3.2 219 3/8/2024
1.3.1 427 2/22/2024
1.3.0 162 2/21/2024
1.2.1 343 2/8/2024
1.2.0 181 2/5/2024
1.1.3 185 2/2/2024
1.1.2 128 2/1/2024
1.1.1 162 1/27/2024
1.1.0 156 1/25/2024
1.0.4 5,209 5/21/2023
1.0.3 354 5/14/2023
1.0.2 2,452 12/3/2022
1.0.1 2,067 7/26/2022
1.0.0 1,127 7/19/2022

Version 1.1.2
Fixed issue with ARM64
Version 1.1.1
Fixed issue with Xamarin.Build.Download
Replaced problematic iOS.UserMessagingPlatform with custom one
Version 1.1.0
Support for .Net8
Added UMP support for mandatory consent for EU users (available only in the licensed version)
Updated Xamarin.GooglePlayServices.Ads.Lite to 122.3.0.2