Bug 39783 - Calling iOS Google Cloud Messaging package's 'AppDidReceiveMessage' Method crashes the application if the received message was sent to a topic
Summary: Calling iOS Google Cloud Messaging package's 'AppDidReceiveMessage' Method cr...
Status: RESOLVED ANSWERED
Alias: None
Product: Components
Classification: Xamarin
Component: Xamarin Components ()
Version: Production (addons.xamarin.com)
Hardware: Other Other
: --- normal
Target Milestone: ---
Assignee: Israel Soto [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-03-18 22:59 UTC by ivansergchub@gmail.com
Modified: 2017-11-23 05:02 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description ivansergchub@gmail.com 2016-03-18 22:59:06 UTC
Summary:

I'm trying to add push notifications to my iOS Xamarin application. I'm using this Xamarin-owned package: https://components.xamarin.com/view/googleiosgcm. I can receive and process notifications sent directly to my specific device using the registration token. However, if I subscribe to a topic using this package, then send a notification to that topic, calling `AppDidRecieveMessage` crashes the application.

OS: iOS 9

Steps to reproduce:

1) Have the following code in AppDelegate:

public override void DidReceiveRemoteNotification (
    UIApplication application, 
    NSDictionary userInfo, 
    Action<UIBackgroundFetchResult> completionHandler)
{

    // my custom notification handler
    Notifications.HandleRecievedNotification (application, userInfo, completionHandler);

    // the line below crashes my app if the message was sent to a topic
    Service.SharedInstance.AppDidReceiveMessage (userInfo);
}

2) Send a notification to a topic that the app subscribed to (for example "/topics/global").
3) observe the crash after the `AppDidRecieveMessage` method is called.
Comment 1 Israel Soto [MSFT] 2016-03-22 18:09:17 UTC
Hi,

Can you provide an isolated test case with the issue, please? Also, can you provide the  log where the crash appears?

Greetings,
Israel Soto.
Comment 2 ivansergchub@gmail.com 2016-03-22 20:42:41 UTC
Below is my json-encoded post request to the GCM server which delivers the notification to my phone.
 
{"content_available":true,"data":{"URI":null},"notification":{"body":"test body","icon":"icon","title":" test title"},"to":"\/topics\/debug"}

The C# code is copied precisely from the documentation of the plugin.

After I call `Service.SharedInstance.AppDidReceiveMessage`, the app crashes. Here’s the log starting at the crash:

2016-03-22 13:34:22.407 AppSheet[871:302645] *** Assertion failure in +[GMRMeasurement sharedInstance], googlemac/iPhone/Greenhouse/Measurement/Library/Sources/GMRMeasurement.m:126
2016-03-22 13:34:22.419 AppSheet[871:302645] critical: Stacktrace:

2016-03-22 13:34:22.420 AppSheet[871:302645] critical:   at <unknown> <0xffffffff>
2016-03-22 13:34:22.420 AppSheet[871:302645] critical:   at <unknown> <0xffffffff>
2016-03-22 13:34:22.421 AppSheet[871:302645] critical: 
Native stacktrace:

2016-03-22 13:34:22.869 AppSheet[871:302645] critical: 	0   AppSheet                            0x0242f189 mono_handle_native_sigsegv + 240
2016-03-22 13:34:22.869 AppSheet[871:302645] critical: 	1   AppSheet                            0x02435f8b mono_sigsegv_signal_handler + 226
2016-03-22 13:34:22.870 AppSheet[871:302645] critical: 	2   libsystem_platform.dylib            0x22f8d85f _sigtramp + 42
2016-03-22 13:34:22.870 AppSheet[871:302645] critical: 	3   AppSheet                            0x0242dcd5 mini_jit_info_table_find_ext + 72
2016-03-22 13:34:22.870 AppSheet[871:302645] critical: 	4   AppSheet                            0x0242e627 mono_handle_exception_internal + 1822
2016-03-22 13:34:22.870 AppSheet[871:302645] critical: 	5   AppSheet                            0x0242df03 mono_handle_exception + 30
2016-03-22 13:34:22.870 AppSheet[871:302645] critical: 	6   AppSheet                            0x02427bab mono_arm_throw_exception + 106
2016-03-22 13:34:22.870 AppSheet[871:302645] critical: 	7   AppSheet                            0x01245494 throw_exception + 64
2016-03-22 13:34:22.870 AppSheet[871:302645] critical: 	8   AppSheet                            0x0056f09c ObjCRuntime_Runtime_throw_ns_exception_intptr + 28
2016-03-22 13:34:22.870 AppSheet[871:302645] critical: 	9   AppSheet                            0x00caa914 wrapper_native_to_managed_ObjCRuntime_Runtime_throw_ns_exception_intptr + 72
2016-03-22 13:34:22.871 AppSheet[871:302645] critical: 	10  AppSheet                            0x02508fa8 xamarin_throw_ns_exception + 52
2016-03-22 13:34:22.871 AppSheet[871:302645] critical: 	11  AppSheet                            0x0250b0f8 _ZL17exception_handlerP11NSException + 224
2016-03-22 13:34:22.871 AppSheet[871:302645] critical: 	12  CoreFoundation                      0x2325dec9 <redacted> + 644
2016-03-22 13:34:22.871 AppSheet[871:302645] critical: 	13  libobjc.A.dylib                     0x22a1b087 <redacted> + 174
2016-03-22 13:34:22.871 AppSheet[871:302645] critical: 	14  libc++abi.dylib                     0x22a0ce17 <redacted> + 78
2016-03-22 13:34:22.871 AppSheet[871:302645] critical: 	15  libc++abi.dylib                     0x22a0c8f7 __cxa_rethrow + 102
2016-03-22 13:34:22.872 AppSheet[871:302645] critical: 	16  libobjc.A.dylib                     0x22a1af47 objc_exception_rethrow + 42
2016-03-22 13:34:22.872 AppSheet[871:302645] critical: 	17  CoreFoundation                      0x2316c30f CFRunLoopRunSpecific + 650
2016-03-22 13:34:22.872 AppSheet[871:302645] critical: 	18  CoreFoundation                      0x2316c07d CFRunLoopRunInMode + 108
2016-03-22 13:34:22.872 AppSheet[871:302645] critical: 	19  GraphicsServices                    0x24788af9 GSEventRunModal + 160
2016-03-22 13:34:22.872 AppSheet[871:302645] critical: 	20  UIKit                               0x27896785 UIApplicationMain + 144
2016-03-22 13:34:22.872 AppSheet[871:302645] critical: 	21  AppSheet                            0x00ba7da8 wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 272
2016-03-22 13:34:22.873 AppSheet[871:302645] critical: 	22  AppSheet                            0x0042b77c UIKit_UIApplication_Main_string___intptr_intptr + 52
2016-03-22 13:34:22.873 AppSheet[871:302645] critical: 	23  AppSheet                            0x0042b620 UIKit_UIApplication_Main_string___string_string + 204
2016-03-22 13:34:22.873 AppSheet[871:302645] critical: 	24  AppSheet                            0x00219f9c iOSAppSheet_Application_Main_string__ + 188
2016-03-22 13:34:22.873 AppSheet[871:302645] critical: 	25  AppSheet                            0x011f854c wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 256
2016-03-22 13:34:22.873 AppSheet[871:302645] critical: 	26  AppSheet                            0x024385d7 mono_jit_runtime_invoke + 1150
2016-03-22 13:34:22.873 AppSheet[871:302645] critical: 	27  AppSheet                            0x02488f85 mono_runtime_invoke + 88
2016-03-22 13:34:22.873 AppSheet[871:302645] critical: 	28  AppSheet                            0x0248c64b mono_runtime_exec_main + 282
2016-03-22 13:34:22.874 AppSheet[871:302645] critical: 	29  AppSheet                            0x02523474 xamarin_main + 2072
2016-03-22 13:34:22.874 AppSheet[871:302645] critical: 	30  AppSheet                            0x0233f6b9 main + 112
2016-03-22 13:34:22.874 AppSheet[871:302645] critical: 	31  libdyld.dylib                       0x22e18873 <redacted> + 2
2016-03-22 13:34:22.874 AppSheet[871:302645] critical: 
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Thanks,
Ivan
Comment 4 Jon Goldberger [MSFT] 2016-03-29 20:10:57 UTC
As for a test project, the reporting customer states that:

"It is non-trivial for me to provide you with an app that has this issue
isolated. Sending notifications requires that the app is in the app store,
with the correct permissions, and that you have my signing key and the
correct provisioning profile. I assume that the maintainer of this package
already has an app that he/she tests with, all that is required to test
this issue is to send a notification addressed to a topic, and call the
method that I mentioned in the bug report. I copy/pasted my code directly
from the package's sample project, and added one method call to subscribe
to a topic:

Google.GoogleCloudMessaging.PubSub.SharedInstance.Subscribe (
token,
"/topics/global",
new NSDictionary (),
(error) => {
var a = error;
});

Just using the sample project along with that one method should do the
trick, right?"
Comment 5 Israel Soto [MSFT] 2016-03-31 23:04:25 UTC
Ivan,

Sorry for taking so long to give a reply.

I have been making some tests and I have not been able to reproduce the error. I, also, tested your Json but with success.

Can you share your environment info? Also, the app crashes in foreground or in background?

Greetings,
Israel Soto.
Comment 6 ivansergchub@gmail.com 2016-04-12 01:46:24 UTC
Hi Israel, perhaps the `NSDictionary userInfo` parameter within the `DidRecieveRemoteNotification` method could provide some more info? Here's a serialized copy of a notification that I just sent to the phone to the `/topics/debug` topic:

{
    aps =     {
        alert =         {
            body = " test";
            title = " test";
        };
    };
    "gcm.message_id" = "0:1460425157492906%69df7a0e69df7a0e";
    "gcm.notification.uri" = "appsheet://";
    "google.c.a.e" = 1;
    "google.c.a.ts" = 1460425157;
}

Does this look right? Is it the same as what you get when you send a notification to a topic?
Comment 7 ivansergchub@gmail.com 2016-04-12 01:48:49 UTC
Regarding the environment - I'm testing using an iPhone 6 plus on iOS 9.3 (though earlier 9.xx versions also had this crash). The app crashes when receiving this type of notification both in the background and in the foreground.
Comment 8 Israel Soto [MSFT] 2017-11-23 05:02:51 UTC
I´m closing this due Google Cloud Messaging was deprecated and replaced with Firebase Cloud Messaging.