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
623 stars 213 forks source link

Click on Notification, OneSignal.Notifications.addClickListener does not listen when app is background state. [Issue faced flutter 3.24.1] #945

Open istiaksaif opened 2 months ago

istiaksaif commented 2 months ago

Unable to listen addClickListener. previous flutter version worked

print('------- init'); #/this line print when app open print('------- listen'); #//but this line not print

Future<void> oneSignalInitial() async {
    await notificationPermissions();
    String oneSignalAppId = '9e2fd62d-65e4-................';

    OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
    OneSignal.Debug.setAlertLevel(OSLogLevel.none);
    OneSignal.consentRequired(false);
    OneSignal.Notifications.addPermissionObserver((state) {
      print("Has permission $state");
    });

    OneSignal.initialize(oneSignalAppId);
    OneSignal.LiveActivities.setupDefault();
    OneSignal.Notifications.addForegroundWillDisplayListener((event) {
      event.preventDefault();
      event.notification.display();
      _handleForegroundNotification(event.notification);
    });

    OneSignal.User.pushSubscription.addObserver((state) async {
      if (OneSignal.User.pushSubscription.id!=null){
        AppPref.setValue('fcmToken', OneSignal.User.pushSubscription.id!);
      }
    });
    print('------- init');
    OneSignal.Notifications.addClickListener((notification) async {
      print('------- listen');
      var additionalData = notification.notification.additionalData;
      if (additionalData != null) {
        var type = additionalData["type"];
        if (type == "calling") {
          _handleCallNotificationClick(additionalData);
        }
      }
    });

  }

Code of Conduct

octav8us commented 2 months ago

got the same problem here, any workarounds?

nandaprasesoft98 commented 1 month ago

I'm also faced this issue, any solution please?

AmorApp commented 1 month ago

Also facing the same issue

fandofastest commented 2 weeks ago

Also facing the same issue

nan-li commented 2 weeks ago

Hi @istiaksaif

What version of the OneSignal Flutter SDK are you using?

Which platform(s) are affected?

Additionally, the app is in a backgrounded and not killed state?

Where are you calling oneSignalInitial() from?