Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 3 tasks
ChoyCheeWei opened this issue Jan 12, 2024 · 5 comments

Comments

@ChoyCheeWei
Copy link

ChoyCheeWei commented Jan 12, 2024

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?

  • iOS
  • Android

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Dicksenz
Copy link

Dicksenz commented Apr 4, 2024

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

@ihijazi
Copy link

ihijazi commented Aug 3, 2024

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
Copy link

arioul89 commented Aug 9, 2024

@ihijazi

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

@ihijazi
Copy link

ihijazi commented Aug 9, 2024

@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.

@jennantilla
Copy link
Contributor

Thank you for this solution, @ihijazi!

Has this worked for others? Any concern with closing this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants