TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
211 stars 49 forks source link

MAUI iOS app crash when linking takes place and notification is received/tapped #195

Closed steffos closed 1 year ago

steffos commented 1 year ago

We are using the plugin in a Maui app but lately have had problems with crashes. Crashes only occur when the linker has been set to 'Sdk Assemblies Only'. Everything seems to work when no linking is taking place.

When app is in foreground and a notification is received it crashes right away. The XCode Device Console logger outputs:

*** Terminating app due to uncaught exception 'ObjCRuntime.RuntimeException', reason: 'Unable to locate the block to delegate conversion method for the method Plugin.Firebase.CloudMessaging.FirebaseCloudMessagingImplementation.WillPresentNotification's parameter #3. Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new. (ObjCRuntime.RuntimeException)
   at ObjCRuntime.Runtime.GetBlockWrapperCreator(MethodInfo , Int32 )
   at ObjCRuntime.Runtime.GetBlockWrapperCreator(IntPtr , Int32 )
   at ObjCRuntime.Runtime.get_block_wrapper_creator(IntPtr , Int32 , IntPtr& )
'
*** First throw call stack:
(0x18b0c4cb4 0x1841643d0 0x1047c5a7c 0x104ae3270 0x104aeaeec 0x10565cd58 0x18d5249f8 0x18d333d2c 0x18d333ad0 0x18d333910 0x1a1140ac8 0x1a1140904 0x1a1144120 0x1a114403c 0x19258beac 0x19258f91c 0x1a114e24c 0x1a114dde8 0x1a1150694 0x18b18e128 0x18b19a7b4 0x18b11f5e8 0x18b1350d4 0x18b13a3ec 0x1c665035c 0x18d4c6f58 0x18d4c6bbc 0x1047b9bb8 0x10136899c 0x101293c7c 0x101293e5c 0x1013eab9c 0x103<…>

When app is in background and a notification is tapped the following is outputted in the console logger:

*** Terminating app due to uncaught exception 'ObjCRuntime.RuntimeException', reason: 'Unable to locate the block to delegate conversion method for the method Plugin.Firebase.CloudMessaging.FirebaseCloudMessagingImplementation.DidReceiveNotificationResponse's parameter #3. Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new. (ObjCRuntime.RuntimeException)
   at ObjCRuntime.Runtime.GetBlockWrapperCreator(MethodInfo , Int32 )
   at ObjCRuntime.Runtime.GetBlockWrapperCreator(IntPtr , Int32 )
   at ObjCRuntime.Runtime.get_block_wrapper_creator(IntPtr , Int32 , IntPtr& )
'
*** First throw call stack:
(0x18b0c4cb4 0x1841643d0 0x1045624bc 0x1048711e0 0x104879fc8 0x1063f4fd8 0x18d5250a8 0x18d333d2c 0x18d333ad0 0x18d333910 0x1a1140ac8 0x1a1140904 0x1a1144120 0x1a114403c 0x19258beac 0x19258f91c 0x1a114e24c 0x1a114dde8 0x1a1150694 0x18b18e128 0x18b19a7b4 0x18b11f5e8 0x18b1350d4 0x18b13a3ec 0x1c665035c 0x18d4c6f58 0x18d4c6bbc 0x1045565f8 0x103cedb7c 0x103c18e5c 0x103c1903c 0x100faa15<…>

We have tried to explicitly tell the linker to keep Plugin.Firebase but the same crashes still occur.

Anyone have a clue as to why this is happening to us? Could UserNotification stuff be removed by the linker from the Microsoft.iOS assembly all of a sudden?

steffos commented 1 year ago

Problem solved. It was all due to a MtouchExtraArgs in the project file that we had added because Maui initially had some problems with push notification and this was a temporary fix: <MtouchExtraArgs>--optimize:-static-block-to-delegate-lookup</MtouchExtraArgs>

Once removed everything worked as expected :)