Plugin.MauiMTAdmob
1.1.3
See the version list below for details.
dotnet add package Plugin.MauiMTAdmob --version 1.1.3
NuGet\Install-Package Plugin.MauiMTAdmob -Version 1.1.3
<PackageReference Include="Plugin.MauiMTAdmob" Version="1.1.3" />
paket add Plugin.MauiMTAdmob --version 1.1.3
#r "nuget: Plugin.MauiMTAdmob, 1.1.3"
// Install Plugin.MauiMTAdmob as a Cake Addin #addin nuget:?package=Plugin.MauiMTAdmob&version=1.1.3 // Install Plugin.MauiMTAdmob as a Cake Tool #tool nuget:?package=Plugin.MauiMTAdmob&version=1.1.3
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
- Available on Nuget: https://www.nuget.org/packages/Plugin.MauiMTAdmob/
- Install in your MAUI project
This plugin supports:
- Maui (Android and iOS)
DISCLAIMER OF LIABILITY
By using MAUIMtAdmob (the "Plugin"), you agree that:
- The Plugin is provided "as is" without any warranties or guarantees of any kind, either expressed or implied.
- 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.
- 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
The Consent might not work on the iOS simulator. You should test it on a real device.
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 | Versions 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. |
-
net8.0-android34.0
- Microsoft.Maui.Controls (>= 8.0.3)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.3)
- Xamarin.AndroidX.Collection (>= 1.3.0.2)
- Xamarin.AndroidX.Collection.Ktx (>= 1.3.0.2)
- Xamarin.Build.Download (>= 0.11.4)
- Xamarin.Google.UserMessagingPlatform (>= 2.1.0.2)
- Xamarin.GooglePlayServices.Ads.Lite (>= 122.3.0.2)
-
net8.0-ios17.2
- Microsoft.Maui.Controls (>= 8.0.3)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.3)
- MT.Xamarin.Google.iOS.UserMessagingPlatform (>= 1.1.0.3)
- Portable.BouncyCastle (>= 1.9.0)
- Xamarin.Build.Download (>= 0.11.4)
- Xamarin.Google.iOS.MobileAds (>= 8.13.0.3)
-
net8.0-maccatalyst17.2
- Microsoft.Maui.Controls (>= 8.0.3)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.3)
- Xamarin.Build.Download (>= 0.11.4)
-
net8.0-windows10.0.19041
- Microsoft.Maui.Controls (>= 8.0.3)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.3)
- Xamarin.Build.Download (>= 0.11.4)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Plugin.MauiMTAdmob:
Package | Downloads |
---|---|
MetaFrm.Maui.Essentials.net7.0
Meta Framework (Multi platform & Meta management) |
|
MetaFrm.Maui.Essentials.net8.0
Meta Framework (Multi platform & Meta management) |
|
AnchorAppsIT.MAUI.Controls
Package Description |
GitHub repositories (2)
Showing the top 2 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
|
|
marcojak/MauiMTAdmob
|
Version | Downloads | Last updated |
---|---|---|
1.7.0 | 316 | 11/2/2024 |
1.6.4 | 1,356 | 9/17/2024 |
1.6.3 | 908 | 9/3/2024 |
1.6.2 | 208 | 9/1/2024 |
1.6.1 | 193 | 8/30/2024 |
1.6.0 | 407 | 8/23/2024 |
1.5.1 | 880 | 8/9/2024 |
1.5.0 | 190 | 8/8/2024 |
1.4.5 | 972 | 7/9/2024 |
1.4.4 | 279 | 7/5/2024 |
1.4.3 | 452 | 6/18/2024 |
1.4.2 | 1,347 | 4/12/2024 |
1.4.1 | 733 | 3/19/2024 |
1.4.0 | 253 | 3/18/2024 |
1.3.3 | 301 | 3/14/2024 |
1.3.2 | 341 | 3/8/2024 |
1.3.1 | 472 | 2/22/2024 |
1.3.0 | 218 | 2/21/2024 |
1.2.1 | 418 | 2/8/2024 |
1.2.0 | 246 | 2/5/2024 |
1.1.3 | 256 | 2/2/2024 |
1.1.2 | 166 | 2/1/2024 |
1.1.1 | 228 | 1/27/2024 |
1.1.0 | 227 | 1/25/2024 |
1.0.4 | 8,113 | 5/21/2023 |
1.0.3 | 385 | 5/14/2023 |
1.0.2 | 2,699 | 12/3/2022 |
1.0.1 | 2,188 | 7/26/2022 |
1.0.0 | 1,419 | 7/19/2022 |
Version 1.1.3
Fixed crash that might happen on iOS simulator
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