@@ -69,7 +69,7 @@ public:
69
69
// OnMessage() callback in this class. SWIGSTDCALL is used here as C#
70
70
// delegates *must* be called using the stdcall calling convention rather
71
71
// than whatever the compiler defines.
72
- typedef int (SWIGSTDCALL *MessageReceivedCallback)(void * message);
72
+ typedef bool (SWIGSTDCALL *MessageReceivedCallback)(void * message);
73
73
// Function which is used to reference a C# delegate which is called from
74
74
// OnTokenReceived() callback in this class. SWIGSTDCALL is used here as C#
75
75
// delegates *must* be called using the stdcall calling convention rather
@@ -250,7 +250,7 @@ void SendPendingEvents() {
250
250
// Listener.TokenReceivedDelegateMethod respectively.
251
251
internal class Listener : System.IDisposable {
252
252
// Delegate called from ListenerImpl::MessageReceivedCallback().
253
- internal delegate int MessageReceivedDelegate (System.IntPtr message);
253
+ internal delegate bool MessageReceivedDelegate (System.IntPtr message);
254
254
// Delegate called from ListenerImpl::TokenReceivedCallback().
255
255
internal delegate void TokenReceivedDelegate (string token);
256
256
@@ -315,19 +315,23 @@ void SendPendingEvents() {
315
315
// Called from ListenerImpl::MessageReceived() via the
316
316
// messageReceivedDelegate.
317
317
[MonoPInvokeCallback(typeof(MessageReceivedDelegate))]
318
- private static int MessageReceivedDelegateMethod (System.IntPtr message) {
318
+ private static bool MessageReceivedDelegateMethod (System.IntPtr message) {
319
+ bool tookOwnership = false ;
319
320
return ExceptionAggregator.Wrap (() => {
320
321
// Use a local copy so another thread cannot unset this before we use it.
321
322
var handler = FirebaseMessagingInternal.MessageReceivedInternal ;
322
323
if (handler != null) {
324
+ // Take ownership, and track it so that the caller of this knows, even
325
+ // if an exception is thrown, since the C# object will still delete it.
323
326
FirebaseMessageInternal messageInternal = new FirebaseMessageInternal (message, true );
327
+ tookOwnership = true ;
324
328
handler (null, new Firebase.Messaging .MessageReceivedEventArgs (
325
329
FirebaseMessage.FromInternal (messageInternal)));
326
330
messageInternal.Dispose ();
327
- return 1 ;
331
+ return true ;
328
332
}
329
- return 0 ;
330
- }, 0 );
333
+ return false ;
334
+ }, tookOwnership );
331
335
}
332
336
333
337
// Called from ListenerImpl::TokenReceived() via the
0 commit comments