Plugin.MauiMTAdmob
1.0.0
See the version list below for details.
dotnet add package Plugin.MauiMTAdmob --version 1.0.0
NuGet\Install-Package Plugin.MauiMTAdmob -Version 1.0.0
<PackageReference Include="Plugin.MauiMTAdmob" Version="1.0.0" />
paket add Plugin.MauiMTAdmob --version 1.0.0
#r "nuget: Plugin.MauiMTAdmob, 1.0.0"
// Install Plugin.MauiMTAdmob as a Cake Addin #addin nuget:?package=Plugin.MauiMTAdmob&version=1.0.0 // Install Plugin.MauiMTAdmob as a Cake Tool #tool nuget:?package=Plugin.MauiMTAdmob&version=1.0.0
Stop the WAR in Ukraine!
MtAdmob plugin for Xamarin (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, support me
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 20: Google SDK 20 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
This plugin is free of charge and you may use it as you like, but regardless of your situation and usage, I won�t be held responsible of any loss.
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)
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
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);
}
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"/>
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:
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) { } <--
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/>
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 😃
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-android31.0 is compatible. net6.0-ios was computed. net6.0-ios15.4 is compatible. net6.0-maccatalyst was computed. net6.0-maccatalyst15.4 is compatible. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net6.0-windows10.0.19041 is compatible. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Xamarin.Build.Download (>= 0.11.2)
-
net6.0-android31.0
- Xamarin.Build.Download (>= 0.11.2)
- Xamarin.GooglePlayServices.Ads.Lite (>= 121.0.0)
-
net6.0-ios15.4
- System.Runtime.InteropServices.NFloat.Internal (>= 6.0.1)
- Xamarin.Build.Download (>= 0.11.2)
- Xamarin.Google.iOS.MobileAds (>= 8.13.0.1)
-
net6.0-maccatalyst15.4
- System.Runtime.InteropServices.NFloat.Internal (>= 6.0.1)
- Xamarin.Build.Download (>= 0.11.2)
-
net6.0-windows10.0.19041
- Xamarin.Build.Download (>= 0.11.2)
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.6.4 | 1,185 | 9/17/2024 |
1.6.3 | 881 | 9/3/2024 |
1.6.2 | 205 | 9/1/2024 |
1.6.1 | 191 | 8/30/2024 |
1.6.0 | 390 | 8/23/2024 |
1.5.1 | 851 | 8/9/2024 |
1.5.0 | 185 | 8/8/2024 |
1.4.5 | 954 | 7/9/2024 |
1.4.4 | 275 | 7/5/2024 |
1.4.3 | 450 | 6/18/2024 |
1.4.2 | 1,343 | 4/12/2024 |
1.4.1 | 725 | 3/19/2024 |
1.4.0 | 248 | 3/18/2024 |
1.3.3 | 300 | 3/14/2024 |
1.3.2 | 340 | 3/8/2024 |
1.3.1 | 471 | 2/22/2024 |
1.3.0 | 216 | 2/21/2024 |
1.2.1 | 415 | 2/8/2024 |
1.2.0 | 245 | 2/5/2024 |
1.1.3 | 255 | 2/2/2024 |
1.1.2 | 163 | 2/1/2024 |
1.1.1 | 227 | 1/27/2024 |
1.1.0 | 226 | 1/25/2024 |
1.0.4 | 7,773 | 5/21/2023 |
1.0.3 | 384 | 5/14/2023 |
1.0.2 | 2,677 | 12/3/2022 |
1.0.1 | 2,183 | 7/26/2022 |
1.0.0 | 1,417 | 7/19/2022 |
Version 1.0
Support for Banner, Interstitials, Rewarded, RewardedInterstitials