drybnikov / klaviyo_flutter

BSD 3-Clause "New" or "Revised" License
4 stars 9 forks source link

ios push notifications not recieved to Flutter #1

Closed Korpyc closed 1 year ago

Korpyc commented 1 year ago

Hey, I've installed your package, I has Firebase messaging which correctly work with my backend server. But, Klaviyo notifications are not received by Flutter code.

Are you sure that your app getting Klaviyo notifications data inside Flutter code???

The hack, that I've used for handling deeplinks, it's I've added handling on iOS side, like code below. The only problem that I've noticed, app receiving it twice.


import UIKit
import Flutter
import Firebase
import KlaviyoSwift

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
      GeneratedPluginRegistrant.register(with: self)
      if #available(iOS 10.0, *) {
                UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
    }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

}

// deeplink handle
extension AppDelegate {
       override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
          KlaviyoSDK().handle(notificationResponse: response, withCompletionHandler: completionHandler)
        }
    }
drybnikov commented 1 year ago

Thank you for your input, I added this userNotificationCenter function as a delegate in the Flutter plugin and now push tracking and deep-linking on iOS should send to Flutter and work. Could you please try the latest update 0.0.1+5 and back with the results?

Korpyc commented 1 year ago

I've tried, changes work's for me as well. Deeplink was handled. But overall, can't read notification inside the Flutter code, as it's not received by Firebase messaging instance.

drybnikov commented 1 year ago

Did you subscribing to FirebaseMessaging listeners?

FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) => _onBackgroundPushOpenedApp(message));
FirebaseMessaging.onMessage.listen((RemoteMessage message) => _onForegroundPushDisplayed(message));

Or check if the push was received while the app terminated?

RemoteMessage? remoteMessage = await FirebaseMessaging.instance.getInitialMessage();

This RemoteMessage object usually contains a deeplink: message.data['url']

Also nice to have are top level function marked as an entry point for iOS app https://pub.dev/packages/flutter_local_notifications#-usage

Future firebaseMessagingBackgroundHandler(RemoteMessage message) async
Korpyc commented 1 year ago

Yes, those listeners are written and work correctly, because my app successfully receive notifications from backend server & test notifications from Firebase console.

waynepollen commented 7 months ago

This shouldn't have been closed IMO - the last message from @drybnikov only confirmed that the firebase side is working. I am able to send from firebase and the handlers are called however if i send from Klaviyo they are not.