CrossGeeks / FirebasePushNotificationPlugin

Firebase Push Notification Plugin for Xamarin iOS and Android
MIT License
396 stars 178 forks source link

iOS app crashes at FirebasePushNotificationManager.Initialize #388

Open gordonsaxby opened 3 years ago

gordonsaxby commented 3 years ago

🐛 Bug Report

App crashes at FirebasePushNotificationManager.Initialize with error:

{System.NullReferenceException: Object reference not set to an instance of an object. at Plugin.FirebasePushNotification.FirebasePushNotificationManager.Initialize (Foundation.NSDictionary options, System.Boolean autoRegistration) [0x00029] in /Users/runner/runners/2.169.1/work/1/s/Plugin.FirebasePushNotification/FirebasePushNotificationManager.ios.cs:141 at MyApp.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00014] in ....\MyApp\MyApp.iOS\AppDelegate.cs:34 }

Expected behavior

Not to crash

Reproduction steps

Create basic Xamarin Forms project with Visual Studio 2019. Add this Nuget package, add FirebasePushNotificationManager.Initialize(options, true); to AppDelegate.cs. Run on iPhone iOS v14.5

Configuration

Version:

3.3.10

Platform:

jtorvald commented 3 years ago

@gordonsaxby I'm running the same version without problems. Did you add it after Xamarin.Forms.Forms.Init(); ?

gordonsaxby commented 3 years ago

I have followed the video here https://www.youtube.com/watch?v=GNBuaAB8nR8& and also the Android version and added all code, done all setup as per the videos.

The Android App runs fine and can receive notifications from Firebase. The iOS version compiles / installs, starts up and shows the default splash screen for 17 seconds and then the app stops (actually minimises) and debugging stops. No breakpoints within the iOS or shared projects are reached.

jtorvald commented 3 years ago

In your Main.cs replace this; UIApplication.Main(args, null, nameof(AppDelegate)); with:

try
{
    UIApplication.Main(args, null, nameof(AppDelegate));
}
catch (Exception e)
{
    try
    {

        Debug.WriteLine(e.Message);
        Debug.WriteLine(e.StackTrace);
        Debug.WriteLine(e.Source);
        Debug.WriteLine(e.InnerException?.StackTrace);
        Debug.WriteLine(e.InnerException?.Source);

        //var data = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        //var filename = Path.Combine(data, String.Format("crash.txt"));
        //File.WriteAllText(filename, e.Message + "\n-----\n" + e.StackTrace ?? "" + "\n-----\n" + e.Source ?? "" + "\n-----\n");
    }
    catch (DirectoryNotFoundException)
    {
    }
}

and see if that exception gives you a better clue of what is going on.

gordonsaxby commented 3 years ago

It doesn't reach that point. I added a breakpoint to the first WriteLine and it didn't hit it.

BTW, I am currently using a Mac at MacInCloud - could that be causing any issues?

Update: Found a different iPhone and that one does report an error (why on earth isn't my iPhone doing that?!?!?!?)

Object reference not set to an instance of an object.
Thread started: <Thread Pool> #8
[0:]   at Plugin.FirebasePushNotification.FirebasePushNotificationManager.Initialize (Foundation.NSDictionary options, System.Boolean autoRegistration) [0x00029] in /Users/runner/runners/2.169.1/work/1/s/Plugin.FirebasePushNotification/FirebasePushNotificationManager.ios.cs:141 
  at MyApp.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00030] in C:\Development\MyApp\trunk\MyApp\MyApp\MyApp.iOS\AppDelegate.cs:62 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65 
  at MyApp.iOS.Application.Main (System.String[] args) [0x00002] in C:\Development\MyApp\trunk\MyApp\MyApp\MyApp.iOS\Main.cs:17
jtorvald commented 3 years ago

@gordonsaxby if you don't mind sharing your code (under NDA), I could have a quick look on my Macbook. I see that this issue is reported here a couple of times. I don't have it so I think I will be able to figure it out. I will send you a tweet so you know how to contact me.

gordonsaxby commented 3 years ago

I now have a physical Mac (MacBook Pro 2018) and the app works fine when run in debug mode from it (using Visual Studio 2019 for Mac). So, I can at least continue development, I just have to do testing of the iOS app from the MacBook.

Not really a solution, but at least shows the plugin does work. And that there is some sort of issue with using it via Windows.

ThePharaon commented 3 years ago

@jtorvald i have same issue on iPhone 7 iOS v14.6 and package version 3.3.10

proximus323 commented 3 years ago

I have the same issue, can some one fix this ?

Paulpetta668 commented 3 years ago

I had the same issue.

It was that it couldn't find the GoogleService-info.plist, I resolved it by set the build option of the file: image

I don't know if this can help you.

proximus323 commented 3 years ago

Paulpetta668 you work on Windows or MacOS ?

Paulpetta668 commented 3 years ago

Paulpetta668 you work on Windows or macOS?

I work on Windows

projectdownton commented 3 years ago

I'm having exactly the same problem with VS in Windows. Already checked Build Action for GoogleService-info.plist and all the configurations... In Android works like a charm.

Could it be possible to have a fix or workaround?

Paulpetta668 commented 3 years ago

I'm having exactly the same problem with VS in Windows. Already checked Build Action for GoogleService-info.plist and all the configurations... In Android works like a charm.

Could it be possible to have a fix or workaround?

Other than the build action I see no workarounds neither fixes. Are u using the simulator?

projectdownton commented 3 years ago

No, a physical iPhone

proximus323 commented 3 years ago

For now it only works from Mac.

rkotulan commented 3 years ago

We have the same issue, any idea how to fix this?

proximus323 commented 3 years ago

Install VS on Mac, and create release there, on Windows not working :(

rkotulan commented 3 years ago

We are building on Azure Pipelines with Image: macOS-10.15 with the same result.

rkotulan commented 3 years ago

We fixed our issue adding InvokeOnMainThread

CrossFirebasePushNotification.Current.OnNotificationError += (source, args) =>
                {
                    InvokeOnMainThread(
                        () => new UIAlertView(
                            "Error registering push notifications",
                            args.Message,
                            null as IUIAlertViewDelegate,
                            "OK",
                            null).Show());
                };
leelandclay commented 3 years ago

I'm having the same issue on a mac. I'm using VS 2019 for Mac with an iPhone 8 (14.0.1). I followed the same video by Gerald. The app opens to a blue screen for about 2 seconds and then disappears. The debugger spins and eventually times out. I added the try catch block around the UIApplication.Main call as well as the Intiialize call. Neither of them are hit. The only thing that shows in the application output is below. One thing that is different is that I have other Firebase components (Xamarin.Firebase.iOS.Auth(6.2.1.2), Xamarin.Firebase.iOS.Analytics(6.0.4.1), Xamarin.Firebase.iOS.Database(6.1.4), Xamarin.Firebase.iOS.Core(6.1.0.1).

Any suggestions?

*Edit - the iPhone is a physical device 2021-10-05 20:53:23.200 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.IDEDebugger.VariablesViewQuickLookProvider for extension Xcode.IDEDebugger.SpriteKitQuickLookProvider of plug-in com.apple.IDESpriteKitParticleEditor 2021-10-05 20:53:23.201 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.IDEDebugger.VariablesViewQuickLookProvider for extension Xcode.SpriteKit.GKStateMachineQuickLookProvider of plug-in com.apple.IDESpriteKitParticleEditor 2021-10-05 20:53:23.213 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.IDEDebugger.VariablesViewQuickLookProvider for extension Xcode.IDEDebugger.GPUMatrixQuickLookProvider of plug-in com.apple.dt.gpu.GPUDebugger 2021-10-05 20:53:23.213 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.IDEDebugger.VariablesViewQuickLookProvider for extension Xcode.IDEDebugger.MTLDebugSamplerState of plug-in com.apple.dt.gpu.GPUDebugger 2021-10-05 20:53:23.213 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.IDEDebugger.VariablesViewQuickLookProvider for extension Xcode.IDEDebugger.MTLDebugTexture of plug-in com.apple.dt.gpu.GPUDebugger 2021-10-05 20:53:23.213 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.IDEDebugger.VariablesViewQuickLookProvider for extension Xcode.IDEDebugger.GPUIssueQuickLookProvider of plug-in com.apple.dt.gpu.GPUDebugger 2021-10-05 20:53:23.214 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.IDEDebugger.VariablesViewQuickLookProvider for extension Xcode.IDEDebugger.MTLDebugBuffer of plug-in com.apple.dt.gpu.GPUDebugger 2021-10-05 20:53:23.214 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.DebuggerFoundation.ViewDescriber for extension Xcode.DebuggerFoundation.watchOSSimulator.ViewDescriber of plug-in com.apple.dt.IDEWatchSupportUI 2021-10-05 20:53:23.214 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.DebuggerFoundation.DataSourceConnection for extension Xcode.DebuggerFoundation.watchOSSimulator.DataSourceConnectionTargetHub of plug-in com.apple.dt.IDEWatchSupportUI 2021-10-05 20:53:23.214 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.DebuggerFoundation.ViewDescriber for extension Xcode.DebuggerFoundation.watchOS.ViewDescriber of plug-in com.apple.dt.IDEWatchSupportUI 2021-10-05 20:53:23.214 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.DebuggerFoundation.DataSourceConnection for extension Xcode.DebuggerFoundation.watchOS.DataSourceConnectionTargetHub of plug-in com.apple.dt.IDEWatchSupportUI 2021-10-05 20:53:23.215 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.DebuggerFoundation.DataSourceConnection for extension Xcode.DebuggerFoundation.tvOSSimulator.DataSourceConnectionTargetHub of plug-in com.apple.dt.IDEAppleTVSupportUI 2021-10-05 20:53:23.215 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.DebuggerFoundation.ViewDescriber for extension Xcode.DebuggerFoundation.ATVSimulator.ViewDescriber of plug-in com.apple.dt.IDEAppleTVSupportUI 2021-10-05 20:53:23.215 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.DebuggerFoundation.ViewDescriber for extension Xcode.DebuggerFoundation.ATV.ViewDescriber of plug-in com.apple.dt.IDEAppleTVSupportUI 2021-10-05 20:53:23.215 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.DebuggerFoundation.DataSourceConnection for extension Xcode.DebuggerFoundation.tvOS.DataSourceConnectionTargetHub of plug-in com.apple.dt.IDEAppleTVSupportUI 2021-10-05 20:53:23.215 mlaunch[11846:232770] Requested but did not find extension point with identifier Xcode.DebuggerFoundation.DeviceIconProvider for extension Xcode.DebuggerFoundation.DeviceIconProvider.AppleTV of plug-in com.apple.dt.IDEAppleTVSupportUI Launched application 'com.kaolinsoftware.polyamdate' on 'Leeland???s iPhone' with pid 532 dyld: dependent dylib '@rpath/protobuf.framework/protobuf' not found for '/private/var/containers/Bundle/Application/2FBF94D8-A0BB-4DEB-A04A-62F01DF59647/Kaolin.PolyAmDate.Mobile.iOS.app/Frameworks/FirebaseMessaging.framework/FirebaseMessaging', tried but didn't find: '/private/var/containers/Bundle/Application/2FBF94D8-A0BB-4DEB-A04A-62F01DF59647/Kaolin.PolyAmDate.Mobile.iOS.app/Frameworks/protobuf.framework/protobuf' '/private/var/containers/Bundle/Application/2FBF94D8-A0BB-4DEB-A04A-62F01DF59647/Kaolin.PolyAmDate.Mobile.iOS.app/Frameworks/FirebaseMessaging.framework/Frameworks/protobuf.framework/protobuf' '@rpath/protobuf.framework/protobuf' '/System/Library/Frameworks/protobuf.framework/protobuf' Application 'com.kaolinsoftware.polyamdate' terminated (with exit code '' and/or crashing signal '6).

BierDav commented 2 years ago

Same problem. Does somebody know a workaround with Windows?

nmano2188 commented 2 years ago

Facing same problem. Any workaround?

omarsolarte commented 2 years ago

face the same problem, help

omatrot commented 1 year ago

Same issue with an iPhone 13 connected to a Mac M1.

robertev-alchemy commented 1 year ago

Facing the same problem, and if this was closed "fixed" I would love to know what the fix was, version, details, example that actually works. There's no details.

So does that mean effectively iOS remote notifications are completely blocked/broken for MAUI?

Does anyone have this actually working - now?

I've tried with Shiny, community toolkit, Plugin.Firebase, and others... no luck.

After struggling with this for a week now I am about to throw in the towel and hire a SWIFT developer instead.

polieadie commented 1 year ago

I solved mine by adding the firebase core initialization above LoadApplication. Sample code is below:

`Firebase.Core.App.Configure();

LoadApplication(new App());

FirebasePushNotificationManager.Initialize(options, true);`

Hope this helps anyone.

dgarcia2105 commented 1 year ago

hi Polieadie I tried but it didn't work

dgarcia2105 commented 1 year ago

I solved mine by adding the firebase core initialization above LoadApplication. Sample code is below:

`Firebase.Core.App.Configure();

LoadApplication(new App());

FirebasePushNotificationManager.Initialize(options, true);`

Hope this helps anyone.

ty for help but i have the same error

{System.NullReferenceException: Object reference not set to an instance of an object. at Plugin.FirebasePushNotification.FirebasePushNotificationManager.Initialize (Foundation.NSDictionary options, System.Boolean autoRegistration) [0x00029] in /Users/runner/work/1/s/Plugin.FirebasePushNotification/FirebasePushNotificationManager.ios.cs:141 at Admh.Clientes.Movil.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00013] in C:\Proyectos\admh\Admh.Clientes.Movil.iOS\AppDelegate.cs:69 at (wrapper managed-to-native) UIKit.UIApplication.xamarin_UIApplicationMain(int,intptr,intptr,intptr,intptr&) at UIKit.UIApplication.UIApplicationMain (System.Int32 argc, System.String[] argv, System.IntPtr principalClassName, System.IntPtr delegateClassName) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.4.0.6/src/Xamarin.iOS/UIKit/UIApplication.cs:58 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00013] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.4.0.6/src/Xamarin.iOS/UIKit/UIApplication.cs:84 at Admh.Clientes.Movil.iOS.Application.Main (System.String[] args) [0x00002] in C:\Proyectos\admh\Admh.Clientes.Movil.iOS\Main.cs:26 }

dgarcia2105 commented 1 year ago

btw i am working in visual studio windows xamarin.ios

dgarcia2105 commented 1 year ago

Help please someone!

polieadie commented 1 year ago

Please try below as well.

image

dgarcia2105 commented 1 year ago

Please try below as well.

image

thanks for your prompt response, I already tried but it didn't work

I am working from my windows laptop remotely connected to my mac

I followed the tutorial: https://www.youtube.com/watch?v=GNBuaAB8nR8&ab_channel=GeraldVersluis

I get the token, connected from the emulator, but when I try to test sending a notification from firebase messaging it never arrives,

I try to use my physical iPad but it returns the following error:

{System.NullReferenceException: Object reference not set to an instance of an object. at Plugin.FirebasePushNotification.FirebasePushNotificationManager.Initialize (Foundation.NSDictionary options, System.Boolean autoRegistration) [0x00029] in /Users/runner/work/1/s/Plugin.FirebasePushNotification/FirebasePushNotificationManager.ios.cs:141 at Plugin.FirebasePushNotification.FirebasePushNotificationManager.Initialize (Foundation.NSDictionary options, Plugin.FirebasePushNotification.NotificationUserCategory[] notificationUserCategories, System.Boolean autoRegistration) [0x00000] in /Users/runner/work/1/s/Plugin.Fire basePushNotification/FirebasePushNotificationManager.ios .cs:176 at Admh.Clientes.Movil.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00013] in C:\Proyectos\admh\Admh.Clientes.Movil.iOS\AppDelegate.cs:47 at (wrapper managed-to-native) UIKit.UIApplication.xamarin_UIApplicationMain(int,intptr,intptr,intptr,intptr&) at UIKit.UIApplication.UIApplicationMain (System.Int32 argc, System.String[] argv, System.IntPtr principalClassName, System.IntPtr delegateClassName) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.4.0.6/ src/Xamarin.iOS/UIKit/UIApplication.cs:58 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00013] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.4.0.6/src/Xamarin.iOS /UIKit/UIApplication.cs:84 at Admh.Customers.Mobile.iOS.Application.Main (System.String[] args) [0x00002] in C:\Projects\admh\Admh.Customers.Mobile.iOS\Main.cs:26 }

dgarcia2105 commented 1 year ago

when i use postman it returns:

{ "multicast_id": 4097073816387638982, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "NotRegistered" } ] }

carlosarizap commented 1 year ago

Any fix? Same issue xamarin.ios on Windows VS Code 2022.

rkotulan commented 1 year ago

We ended up abandoning the use of this plugin and implemented FCM services directly. This plugin uses the old method to get the token. Now the notifications and GA4 work well for us again with the current versions of the google libraries.

SliemBeji-FBC commented 1 year ago

We ended up abandoning the use of this plugin and implemented FCM services directly. This plugin uses the old method to get the token. Now the notifications and GA4 work well for us again with the current versions of the google libraries.

Can you please share your solution because i struggel with it myself for over 2 weeks now