MarcTron.Admob version 1.4.3 is here
UPDATE: It seems there is a problem with Xamarin.Google.iOS.MobileAds version 7.47.0 that doesn’t allow you to compile your code. If this happens, downgrade Xamarin.Google.iOS.MobileAds to version 7.38.0
I’eve just released the new version of the best and most complete Google Admob plugin for Xamarin (Android and iOS).
The changes for this version are:
- Added Consent option to iOS
- Updated Xamarin.Google.iOS.MobileAds to 7.47.0
With this new version it is possible to decide if use personalised Ads or not on iOS.
In addition to this, the new version of Xamarin.Google.iOS.MobileAds should solve some issues with iOS 13.
How to use the plugin
With MarcTron.Admob you can add Banners, Interstitials and Rewarded Videos to your apps with a single line of code.
First of all, install the plugin from Nuget: https://www.nuget.org/packages/MarcTron.Admob/ . Remember to install it in you shared project and in your Android and iOS projects.
After installing it, in your Android project open your AndroidManifest.xaml and inside the application tag insert this code:
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx"/>
Remember to use your actual ApplicationID (you can find it in you Admob dashboard).
If on iOS you have problems displaying your ads, install the Xamarin.Google.iOS.MobileAds plugin (it should be installed automatically but sometimes you have to do it manually).
Add a Banner
To add a Banner, in your XAML add the code:
<controls:MTAdView/>
remember to add this line in your XAML:
xmlns:controls="clr-namespace:MarcTron.Plugin.Controls;assembly=Plugin.MtAdmob"
That’s it.
If you have problems showing the Ads, try to set the style in App.xaml:
<OnIdiom x:TypeArguments="x:Double" x:Key="AdsHeight" Phone="50" Tablet="90"/>
<Style TargetType="controls:MTAdView">
<Setter Property="HeightRequest" Value="{StaticResource AdsHeight}"/>
</Style>
Interstitials
You can add an Insterstitial with a single line of code:
CrossMTAdmob.Current.ShowInterstitial();
To load a new one:
CrossMTAdmob.Current.LoadInterstitial("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");
Rewarded Video
You can show a Rewarded video with a single line of code:
CrossMTAdmob.Current.ShowRewardedVideo();
To Load a Rewarded Video you can use this line:
CrossMTAdmob.Current.LoadRewardedVideo("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");
There is so much more
There are many other things you can do with this great plugin for Admob. You can find the full documentation here: https://www.xamarinexpert.it/admob-made-easy/
Gennaro
May 15, 2022 @ 10:36 pm
Ciao Marc, what about “App Open” ad unit? do you think to implement also it ? thank you
Gs
February 7, 2022 @ 9:22 am
first of all thank you for your job
is it possible to explain how you do the attachment on a framelayout view knowing that I have a particular project that does not have a monogame game engine xaml file thank you
Martin Stein
September 30, 2021 @ 5:00 pm
Hi,
I am wondering if MarcTron.Admob is running under Microsofts MAUI-environment?
Marco Troncone
September 30, 2021 @ 4:02 pm
Hi Martin, I haven’t tried yet but given that I use the plugin for all my apps, and I really want to move to MAUI as soon as it will be available (next year at this point), I’ll make all the necessary changes that might be required to support it.
Thomas Eric Paronis
September 28, 2021 @ 6:12 pm
Good to know. I shall do that. The Android version is in the marketplace and today i work on the iOS version. I’m assuming (hoping) that this will work when Xamarin morphs into Maui.
Thomas Eric Paronis
September 25, 2021 @ 4:59 pm
Hello Marco. I’m using your plug in for interstitials and it looks like it is a HUGE time saver for me and lets me concentrate on the core IP. However, I have a question regarding CrossMTAdmob.Current.LoadInterstitial(“ca-app-40256099942544/1033173712”). When is the optimal time to call it. The first time I call it it doesn’t show the ad. Should I do it when the app starts up and then call it again after I show an interstitial? Thanks!
Marco Troncone
September 25, 2021 @ 5:34 pm
Hi Thomas, thank you.
LoadInterstitial just loads the interstitial, then you need to use ShowInterstitial to actually show it. I’d suggest you to call LoadInterstitial in advance as it could take some time to load it (usually it takes just few instants but it depends on many factors). Your approach is very sensible, loading it when the app starts and then every time you show an interstitial.
Gennaro ingenito
February 27, 2021 @ 9:45 pm
Ciao Marco. i have the events on two different controls and both of them are raised when video is rewarded due static “current” property. have i to manage it via control visibility or there is a way to use two different istances? thank you
Gennaro ingenito
February 27, 2021 @ 9:40 pm
Ciao Marco, Is it possible to know the rewarded amount before to show video? i’d like to have a “+x credits” button to show video
Brookey
November 4, 2020 @ 6:36 am
I’m having difficulty implementing AdMob in a rudimentary app and was encouraged by the concept of the MarcTron NuGet package but that is not working for me either.
The following is from the Output:
NU1605: Detected package downgrade: Microsoft.NETCore.UniversalWindowsPlatform from 6.2.9 to 6.1.9. Reference the package directly from the project to select a different version.
GrimeTester.UWP -> Xamarin.Essentials 1.5.3.2 -> Microsoft.NETCore.UniversalWindowsPlatform (>= 6.2.9)
GrimeTester.UWP -> Microsoft.NETCore.UniversalWindowsPlatform (>= 6.1.9)
1>—— Build started: Project: GrimeTester.Android, Configuration: Debug Any CPU ——
1>C:\Users\grime.nuget\packages\xamarin.androidx.migration\1.0.0.1\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : Could not find 36 Android X assemblies, make sure to install the following NuGet packages:
1>C:\Users\grime.nuget\packages\xamarin.androidx.migration\1.0.0.1\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : – Xamarin.AndroidX.Lifecycle.LiveData
1>C:\Users\grime.nuget\packages\xamarin.androidx.migration\1.0.0.1\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : – Xamarin.AndroidX.Browser
1>C:\Users\grime.nuget\packages\xamarin.androidx.migration\1.0.0.1\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : – Xamarin.Google.Android.Material
1>C:\Users\grime.nuget\packages\xamarin.androidx.migration\1.0.0.1\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : – Xamarin.AndroidX.Legacy.Support.V4
1>C:\Users\grime.nuget\packages\xamarin.androidx.migration\1.0.0.1\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : You can also copy-and-paste the following snippet into your .csproj file:
1>C:\Users\grime.nuget\packages\xamarin.androidx.migration\1.0.0.1\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error :
1>C:\Users\grime.nuget\packages\xamarin.androidx.migration\1.0.0.1\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error :
1>C:\Users\grime.nuget\packages\xamarin.androidx.migration\1.0.0.1\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error :
1>C:\Users\grime.nuget\packages\xamarin.androidx.migration\1.0.0.1\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error :
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
If you need more please let me know. I’d like to nail this is the next few days.