marius-bughiu / Plugin.AdMob

.NET MAUI plugin for AdMob
https://startdebugging.net
MIT License
30 stars 4 forks source link

GetRootViewController is null in CreatePlatformView #8

Open jmichas opened 2 weeks ago

jmichas commented 2 weeks ago

I am using MAUI 8 with Shiny Framework which is a combination of Shiny and Prism. My problem is that when the handler is applied to the BannerAd control, the UIViewController cannot be retrieved.

It appears to be always null at every stage of the handler creation, but is available in FinishedLaunching after calling base.FinishedLaunching(application, launchOptions) which occurs after then ad handler is fully initialized and created.

The BannerAd is on the first page of my app. So I am not sure what to do to correct this.

Also, for MAUI I think you can change the code for GetRootViewController to: Microsoft.Maui.ApplicationModel.Platform.GetCurrentUIViewController();

The code you are using hasa been deprecated.

jmichas commented 2 weeks ago

Wow, so in writing this up I thought of a really easy low tech solution. I added a "SplashPage" to my project that is loaded first, in the OnAppearing handler for the SplashPage I load my Main page that contains the banner ad. Problem solved. FinishedLaunching has completed and the handler isn't applied for the BannerAd until after that. So, if anyone is using a banner on the initial page of their app they may have this problem, or maybe it is just because I use Shiny/Prism, not sure.