OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

OneSignal.Notifications.addClickListener does not fire on push notification tap when app is killed

Open nandaprasesoft98 opened this issue 1 year ago • 7 comments
trafficstars

How can we help?

Hi,

I just reopen this issues (https://github.com/OneSignal/OneSignal-Flutter-SDK/issues/723) that in 5.2.2 is still same issue in original firebase, using FirebaseMessaging.onMessageOpenedApp.listen, if in background mode and clicking notification, the listener callback is called. But if in one signal (OneSignal.Notifications.addClickListener), the listener callback is not called

Anyone who helps solve this problem, I would like to thank you very much

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

nandaprasesoft98 avatar Jul 04 '24 09:07 nandaprasesoft98

I also face that kinds of issue on 5.2.0 . Please help me out!

MayZarHlaing avatar Jul 24 '24 10:07 MayZarHlaing

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.

ihijazi avatar Aug 03 '24 14:08 ihijazi

Solution given by @ihijazi should work for most of the people, but the problem is home_widget plugin which registers background callback for interactive widget on iOS 17 asynchronously, which is causing the problem for onesignal. This is the problem

 if #available(iOS 17, *) {
   HomeWidgetBackgroundWorker.setPluginRegistrantCallback { registry in
    GeneratedPluginRegistrant.register(with: registry)
    }
  }

To fix this, I am re-registering onesignal plugin after setting the background callback for home_widget.

private func reregisterOneSignal(){
        OneSignalPlugin.register(with: self.registrar(forPlugin: "OneSignalPlugins")!)
        print("OneSignalPlugin reregistered")
    }

Calling it in flutter like this

await HomeWidget.registerInteractivityCallback(backgroundCallback);
await platform.invokeMethod<bool>('reregisterOneSignal');

Praveena0989 avatar Aug 24 '24 05:08 Praveena0989

I am comfronting same issue, and @ihijazi solution did not work for me 😓

My appDelegate looks like this

import Flutter
import UIKit
import flutter_background_service_ios
import FirebaseCore
import app_links

@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    SwiftFlutterBackgroundServicePlugin.taskIdentifier = "id.flutter.flutter_background_service.BackgroundService"
    
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    
    GeneratedPluginRegistrant.register(with: self)

    // Retrieve the link from parameters
    if let url = AppLinks.shared.getLink(launchOptions: launchOptions) {
      // We have a link, propagate it to your Flutter app or not
      AppLinks.shared.handleLink(url: url)
      return true // Returning true will stop the propagation to other packages
    }

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

  override func application(
    _ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
  ) -> Bool {
    if let incomingURL = userActivity.webpageURL {
      // Handle the Universal Link in Flutter
      AppLinks.shared.handleLink(url: incomingURL)
      return true  // Indicate that the URL has been handled
    }
    return false
  }
}

vdiaza avatar Aug 29 '24 01:08 vdiaza

No updates on this? My app is working on a very important functionality and it depends 100% on this feature. Any workaround at least so I can keep working on my app?

Gonzalo-Bruna avatar Apr 14 '25 01:04 Gonzalo-Bruna

Any update on this?

chornthorn avatar Apr 30 '25 07:04 chornthorn

I got the same issue

Kimsoer avatar May 01 '25 12:05 Kimsoer