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

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

Open
1 task done
nandaprasesoft98 opened this issue Jul 4, 2024 · 4 comments

Comments

@nandaprasesoft98
Copy link

How can we help?

Hi,

I just reopen this 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

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

MayZarHlaing commented Jul 24, 2024

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

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

@Praveena0989
Copy link

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');

@vdiaza
Copy link

vdiaza commented Aug 29, 2024

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
  }
}

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