marcojak / MauiMTAdmob

MIT License
104 stars 17 forks source link

Page crash when load Adbanner #19

Closed banhthanhvi closed 1 year ago

banhthanhvi commented 1 year ago

xmlns:admod="clr-namespace:Plugin.MauiMTAdmob.Controls;assembly=Plugin.MauiMtAdmob" <admod:MTAdView Grid.Row="2" x:Name="myAds" AdSize="AnchoredAdaptive" IsVisible="true" AdsId="{Binding AdbannerId}" VerticalOptions="End" HeightRequest="{OnIdiom Phone=50, Tablet=90, Desktop=90}" />

My MAUI page has crash when add above code. I use:

Do I miss something? Thank you.

banhthanhvi commented 1 year ago

It crashes on build iOS release.

DeerSteak commented 1 year ago

I think this is a Xamarin.Google.iOS.MobileAds issue - if you call MobileAds.SharedInstance.Start in AppDelegate, it crashes because MobileAds.SharedInstance is null. Since this plugin relies on the Xamarin library, my guess is it's quietly doing the same thing.

You can test it by making this your AppDelegate. If you comment out the first line in FinishedLaunching it won't crash. You can also refer to this bug in the Xamarin GitHub: https://github.com/xamarin/GoogleApisForiOSComponents/issues/592

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
    protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        MobileAds.SharedInstance.Start(AdsCompletionHandler);

        return base.FinishedLaunching(application, launchOptions);
    }

    private void AdsCompletionHandler(InitializationStatus status) { }
}
Martinedo commented 1 year ago

was there any progress on this issue? it still occurs

marcojak commented 1 year ago

Does the sample work for you?

On Sat, 15 Apr 2023, 21:09 Martinedo, @.***> wrote:

was there any progress on this issue? it still occurs

— Reply to this email directly, view it on GitHub https://github.com/marcojak/MauiMTAdmob/issues/19#issuecomment-1509929715, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUIPIR5SVAOXZ3WGYRPSEDXBLW7FANCNFSM6AAAAAATKBE7YY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Martinedo commented 1 year ago

I tried the sample and it worked. Then I compared it with my solution and the problem was not with the library or the code, but with my target version of iOS, which was set too low on 11, I tested it on the same as in the sample 14.2 and it works! thank you :)

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>

I tested different versions and iOS 12 is not supported, so iPhone 5S and 6 are unlucky. every newer iphone should be ok.

Znow commented 1 year ago

@marcojak

Does not work on iOS 16.4.1...

"Object reference not set to an instance of an object" when adding a banner either by C# code or XAML

marcojak commented 1 year ago

From version 1.0.3 this problem should have been solved.