Plugin.AdMob
Plugin.AdMob copied to clipboard
Interstitials not working
Hello, I am trying to get Interstitial ads working in my .NET Maui application. It is currently failing on both iOS and Android.
In my view model, I am retrieving the singleton IInterstitialAdService from Service provider and running: _interstitialAdService.PrepareAd("{MY_AD_UNIT_ID}");
Then, on button click I am running: _interstitialAdService.ShowAd();
On that method call, my app crashes with an error: System.ArgumentNullException: Value cannot be null. (Parameter 'adUnitId') at ObjCRuntime.ThrowHelper.ThrowArgumentNullException(String argumentName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/ThrowHelper.cs:line 28 at Google.MobileAds.InterstitialAd.Load(String adUnitId, Request request, InterstitialAdLoadCompletionHandler completionHandler) at Plugin.AdMob.Services.InterstitialAdService.PrepareAd(String adUnitId) at Plugin.AdMob.Services.InterstitialAdService.ShowAd()
When I inspect _insterstitialAdService, I can see the private property "_ad" is indeed populated and it's AdUnitId property is populated with my ad unit id.
I've also tested using the test unit id's here: https://developers.google.com/admob/ios/test-ads#demo_ad_units with the same result.
Am I doing something wrong or is this a bug?
Additionally, it doesn't seem like AddTestDevice is working. When I run the application on my simulator, I am able to see a Test Ad banner. However, when I try running on my device, I am not able to see the banner.
In my MauiProgram.cs, I am executing: AdConfig.AddTestDevice("{MY_TEST_DEVICE_AD_ID}");
This device has been added to AdMob as a test device with a matching Ad ID.
In the console, I see a message: <Google> To get test ads on this device, set: Objective-C GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = @[ @"{string of characters}" ]; Swift GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = [ @"{string of characters}" ]
I've tried updating my call to AddTestDevice with the supplied characters from the message, but there was no change.