marcojak / MauiMTAdmob

MIT License
104 stars 17 forks source link

MTAdView control in Xaml throws exception for WinUI apps #8

Closed AntHillOracle closed 4 months ago

AntHillOracle commented 1 year ago

MTAdView control in Xaml throws exception for WinUI apps.

I know that this plugin only functions for Android and iOS but placing the MTAdView control on a page on the WinUI platform results in a run-time exception in InitializeComponent. Any code using the MTAdView compiles fine, it just crashes immediately.

Your Xamarin plugin allows this: an MTAdView on a Xaml Page for Xamarin.UWP uses zero page real estate and the page is fully functional. My Xamarin app for Android, iOS, and UWP is able to use the same Xaml for all platforms.

This crash on Maui hinders its useability for cross-platform development. It is possible to code around this by creating the control in xaml.cs code-behind (inside blocks of "if DevicePlatform.Android or DevicePlatform.iOS") but this obviously isn't ideal.

Ideally, this should function as the plugin does on Xamarin. Allow definition of MTAdView for all platforms which results in initializing a view with height and width of zero.

marcojak commented 1 year ago

Hi,

it's a very good point. I'll update the plugin to have an empty view on Windows and then when a possible alternative for Windows will be found, I will add that as well.

marcojak commented 1 year ago

I've just published version 1.0.2 that should allow you to use the plugin on Windows with no compatibility problems (no ads on Windows yet). Let me know if it works!

AntHillOracle commented 1 year ago

Version 1.0.2 does allow references to the plugin on Windows. Testing worked as I hoped it would. I noticed that one can even make a call to load an interstitial (even though nothing happens obviously). Good stuff. Thank you, Marco.

p.s. I decided to suspend my project's migration to MAUI until it becomes more stable. I'm back to Xamarin and MTAdmob there. Thanks for that recent release.

marcojak commented 4 months ago

The new version doesn't crash anymore on WinUI.