thomasgalliker / Plugin.FirebasePushNotifications

Receive and handle firebase push notifications in .NET MAUI apps
MIT License
66 stars 5 forks source link

[Bug] SharedInstance is null #12

Closed thomasgalliker closed 6 months ago

thomasgalliker commented 6 months ago

@TedMobile reported this on Oct 20, 2023: "I tried your plugin and I get the same issues it crashes here.. and again SharedInstance is null. Firebase.CloudMessaging.Messaging.SharedInstance.AutoInitEnabled = defaultOptions.AutoInitEnabled;

See discussion here.

KaraVehizen commented 6 months ago

I think i had this issue and updating to .net and maui to 8+ solved it for me

MPoels commented 6 months ago

I managed to get the android version running, that's running fine now. However the iOS version of my app (maui .net 8.0) and the latest pre-release package 2.2.37. It crashes during startup. If passes the FinishedLaunching in the AppDelegate and then crashes with a null reference exception:

    0x38 in UIKit.UIApplication.xamarin_UIApplicationMain   C#
    0xE in UIKit.UIApplication.UIApplicationMain at /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:58,4    C#
    0x51 in UIKit.UIApplication.Main at /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:94,4    C#
>   0xD in AppSlimladen.Program.Main at D:\GitHub_SmartCharging\Apps\Maui\AppSlimladen\AppSlimladen\Platforms\iOS\Program.cs:13,4   C#

Is this related to the reported bug? As it is not running any of my code I have no idea of what is missing or what is null.

thomasgalliker commented 6 months ago

@MPoels do you have logging in place? I would highly recommend to write logs so we can observe what's going wrong here. Have a look at the sample app; I use NLog there to write logs to local files in order to have a complete picture - even if no debugger is attached to the program.

MPoels commented 6 months ago

I will try that and let you know.

MPoels commented 6 months ago

Running the code in the ios-emulator showed it was a startup issue in my own code calling GetToken() too early. Problem solved and now the ios version runs properly too! Thanks for pointing me in the right direction. It looks like preview 2.2.27 is doing it's job properly! Despite a whole bunch of warnings Again thanks for the help. I can now continue development!