mirzemehdi / KMPNotifier

Kotlin Multiplatform Push Notification Library targetting android and iOS
http://mirzemehdi.com/KMPNotifier/
Apache License 2.0
172 stars 10 forks source link

Notification Click not working when iOS app is closed #31

Closed ivancaas closed 3 weeks ago

ivancaas commented 1 month ago

I might be wrong as I'm not an expert in iOS myself. But when I click the notification with the app in Background/Opened it gets to onNotificationClicked, but when the app is closed and I tap, the app opens but nothing happens as it's not calling that function somehow

mirzemehdi commented 1 month ago

@ivancaas did you do these steps in ios as it is shown in ReadMe?

iOS

Call NotifierManager.onApplicationDidReceiveRemoteNotification(userInfo: userInfo) on application's didReceiveRemoteNotification method.

 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) async -> UIBackgroundFetchResult {
      NotifierManager.shared.onApplicationDidReceiveRemoteNotification(userInfo: userInfo)
      return UIBackgroundFetchResult.newData
 }

Detecting notification click and get payload data

Make sure you follow previous step for getting payload data properly.

NotifierManager.addListener(object : NotifierManager.Listener {
    override fun onNotificationClicked(data: PayloadData) {
        super.onNotificationClicked(data)
        println("Notification clicked, Notification payloadData: $data")
    }
}) 
tamimattafi commented 3 weeks ago

@mirzemehdi @ivancaas In order to handle start arguments, you need to read user Info from didFinishLaunchingWithOptions. That's because didReceiveRemoteNotification will not be called when the app is in the background. https://github.com/mirzemehdi/KMPNotifier/issues/24#issuecomment-2082659684

ivancaas commented 3 weeks ago

@mirzemehdi was right about something missing, apparently I forgot to add the "NotifierManager.shared.initialize" line in the iOS App?... too many hours coding, the rest was OK, after adding it everything works as expected.

Thanks both for your help!