OneSignal / OneSignal-Flutter-SDK

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

[Bug]: both addForegroundWillDisplayListener and addClickListener not triggered with hms (huawei) #822

Open ChoyCheeWei opened 10 months ago

ChoyCheeWei commented 10 months ago

What happened?

Future<void> init() async {
    OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
    OneSignal.Debug.setAlertLevel(OSLogLevel.none);

    OneSignal.initialize(F.oneSignalKey);

    await OneSignal.User.pushSubscription.optIn();

    OneSignal.Notifications.addForegroundWillDisplayListener((
      event,
    ) {
      event.preventDefault();
      LocalNotificationService.showNotification(
        event.notification,
        event.notification.additionalData?['data']['id'] ?? '',
      );
    });

    OneSignal.Notifications.addClickListener((event) {
      if (event.notification.additionalData?['action'] == 'new-order') {
        NotificationHelper.navigate(
          event.notification.additionalData?['data']['id'] ?? '',
        );
      }
    });
  }

It works fine in both Android and ios but it's not being triggered in hms I have following this to setup

I can receive notifications from both Onesignal BO and my backend service, but nothing happens when I click on the notification. No error log is displayed on the terminal also

Steps to reproduce?

1. Setup huawei pushkit
2. Configure huawei platform in OneSignal BO
3. trigger notification from Onesignal BO or your backend service
4. it will show a notification on your Hms phone but nothing happens after you click it

What did you expect to happen?

Same behavior just like Android and ios, both listeners will be triggered when receive or click on the notification

OneSignal Flutter SDK version

5.0.4

Which platform(s) are affected?

Relevant log output

No response

Code of Conduct

Dicksenz commented 7 months ago

I'm getting the same issue on Harmony device. Any fix for that ?

ihijazi commented 3 months ago

Been having similar behavior, not only on cold start.

My app uses some native code for some other SDK. The other SDK had GeneratedPluginRegistrant.register(with: "xxx"), and it was placed AFTER GeneratedPluginRegistrant.register(with: self).

The GeneratedPluginRegistrant.register(with: self) has to be at the very end, for both Android and iOS.

example for swift:

        GeneratedPluginRegistrant.register(with: xxx)

        GeneratedPluginRegistrant.register(with: self) // this has to be at the very end

        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }

Tested with latest 5.2.2 and working fine.. all handlers as expected.

Hope this helps someone.

arioul89 commented 3 months ago

@ihijazi

Moving the line "GeneratedPluginRegistrant.register(with: "xxx")" at the very end, fixed the problem for both Android and iOS ?

ihijazi commented 3 months ago

@ihijazi

Moving the line "GeneratedPluginRegistrant.register(with: "xxx")" at the very end, fixed the problem for both Android and iOS ?

It was already there for Android so can't say if the problem was there in the first place. But it did for iOS.