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

How can I track the opening of app by clicking on a notification? #19

Closed
GimazDo opened this issue Mar 28, 2024 · 9 comments · Fixed by #20
Closed

How can I track the opening of app by clicking on a notification? #19

GimazDo opened this issue Mar 28, 2024 · 9 comments · Fixed by #20

Comments

@GimazDo
Copy link

GimazDo commented Mar 28, 2024

Hi, how can i detect that user clicked on notification?

I need that when I click on a notification, a screen will open depending on the data in the notification.

@Abdelrhman-sbs
Copy link

@ValdZX @mirzemehdi
Please, any help?

@mirzemehdi
Copy link
Owner

I think this is more about adding deeplink support to library. But I am still checking my options

@mirzemehdi
Copy link
Owner

@GimazDo @Abdelrhman-sbs

This is implemented in library version 0.5.0.

This is how you can use it:

Detecting notification click and get payload data

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

You need to call below platform-specific functions in order to receive payload data properly.

Android

Call NotifierManager.onCreateOrOnNewIntent(intent) on launcher Activity's onCreate and onNewIntent methods.

override fun onCreate(savedInstanceState: Bundle?) {
   super.onCreate(savedInstanceState)
      NotifierManager.onCreateOrOnNewIntent(intent)
      ...
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        NotifierManager.onCreateOrOnNewIntent(intent)
    }
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
 }

For more detailed information you can check PR #20

@mirzemehdi
Copy link
Owner

Please, let me know if there is any issue

@emanuelecastelli
Copy link

emanuelecastelli commented Apr 9, 2024

On my side (ios impl) onNotificationClicked callback not get called when app is in background.
I have followed all the conf steps and tried to use UNUserNotificationCenterDelegate too, but without luck.
Can you confirm that on your side package callback is triggered when app is in background?

@mirzemehdi
Copy link
Owner

@emanuelecastelli yes, when I click notification I get listener callback.

  1. Make sure you enabled remote-notificaiton in backgorund modes in XCode.
  2. You added this part in ios part
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) async -> UIBackgroundFetchResult {
        NotifierManager.shared.onApplicationDidReceiveRemoteNotification(userInfo: userInfo)
        return UIBackgroundFetchResult.newData
    }

@emanuelecastelli
Copy link

i have done everything.
When app is in foreground, i din't see the notification, but i get every log that i do in native and in cross.
When app is in background, i see the notification at the top, i tap on it but no log is printed out (nor from native nor from cross). The debugger too not get called in xcode (breakpoint set in didReceiveRemoteNotification ).
App simply returns in foreground.

@emanuelecastelli
Copy link

@mirzemehdi can you provide json body that you use for test push notifications?
I'm using something like that, playing with apns props, but no way :(

{
  "message": {
    "token": ".......",
     "notification": {
      "title": "title",
      "body": "Notification from FCM"
    },
    "apns": {
    
        "headers": {
            
            
        },
        "payload": {
            
        }
    }
  }
}

@emanuelecastelli
Copy link

Ok, restoring FCM method swizzling resolve the issue: push notifications callbacks now runs correctly

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

Successfully merging a pull request may close this issue.

4 participants