0

I know that maybe similar thread has been asked in here How posting One Signal notification's additional data and receiving that? , but as a beginner I am confused how to implement the answer.

so, I try to send push notification through one signal console. and I need to send custom data in order to navigate the user to certain view controller after the user tap the push notification like this

enter image description here

but unfortunately I don't know how to get that key value pairs of that destination and idItem. I assume I have to do something on my AppDelegate , but I don't know how to get that key value pairs when the user interact with the push notification sent.

from that thread, I get

let PATH = notification!.payload.additionalData["PATH"]
print("PATH: ",PATH as Any)

but.... I don't know where to implement this code

sarah
  • 3,819
  • 4
  • 38
  • 80

1 Answers1

1

I finally find the answer. in AppDelegate in didFinishLaunchingWithOptions

OneSignal.initWithLaunchOptions(launchOptions, appId: "YOUR ONE SIGNAL APP ID HERE", handleNotificationAction: { (result) in

            let payload = result?.notification.payload
            if let additionalData = payload?.additionalData {

                let destination = additionalData["destination"] as? String ?? ""
                print("the destination is: \(destination)")

            }


        },settings: onesignalInitSettings)
sarah
  • 3,819
  • 4
  • 38
  • 80