OneSignal / OneSignal-Xamarin-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Xamarin app with OneSignal. https://onesignal.com
Other
105 stars 50 forks source link

OneSignal SDK for Xamarin: HandleNotificationReceived not firing on Huawei device but HandleNotificationOpened it is #221

Closed AndreaMontanari89 closed 2 years ago

AndreaMontanari89 commented 3 years ago

Description:

I am trying to integrate onesignal into the application that I am developing with Xamarin SDK. With android and ios devices everything works fine.

With Hauwei devices I have the problem that the "HandleNotificationReceived" callback is not called but instead the "HandleNotificationOpened" callback is. The notifications arrive anyway and therefore it is suggested that Huawei push kit is configured correctly.

I also tried to extend the "Com.OneSignal.Android.NotificationExtenderService" class but the scenario is the same: with android it is called and with Huawei it is not.

        `OneSignal.Current.StartInit(OneSignalData.AppId)
        .Settings(new Dictionary<string, bool>() {
            { IOSSettings.kOSSettingsKeyAutoPrompt, false },
            { IOSSettings.kOSSettingsKeyInAppLaunchURL, false }, })
        .InFocusDisplaying(OSInFocusDisplayOption.Notification)
        .HandleNotificationOpened((result) =>
        {
            on_notification_action(result);
        })
        .HandleNotificationReceived((notification) =>
        {
            on_notification_received(notification);
        })
        .HandleInAppMessageClicked((action) =>
        {
            // Example IAM click handling for IAM elements
            Debug.WriteLine("HandledInAppMessageClicked: {0}", action.clickName);
        })               
        .EndInit();`

The installed nuGet packages are: Com.OneSignal 3.10.2 and nventive.Com.OneSignal 3.2.13 I am testing the app on a Huawei p40PRO EMUI 10.1.0 Andorid 10.

The power saving app permissions settings should also be fine.

What can it be? Thanks in advance

jkasten2 commented 3 years ago

@HelpFamily-2020 Thanks for reporting. The HandleNotificationReceived currently only fires for "data" type payloads.

OneSignal always sends push payloads as "data" for FCM message so this can fire. However for Huawei devices we default to a "message" payload as "data" payloads don't work when the app is closed.

You can set the huawei_msg_type to "data" if you need the HandleNotificationReceived to fire, however keep in mind that the notification will not show when the app is closed. https://documentation.onesignal.com/reference/create-notification#attachments This option is also available on the OneSignal dashboard.

jkasten2 commented 2 years ago

Closing due to inactivity.