I am working on event implementation and I need to put user_visited event in app launch, coming from background mode, deeplink and push notification. So I have put my event in
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
self.trackUserVisitedEvent()
}
}
func applicationWillEnterForeground(_ application: UIApplication) {
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
self.trackUserVisitedSegEvent()
}
}
with delay of 4 sec because I need to send the app opening source it's - direct, deeplink or push notification because currently from my understanding applicationWillEnterForeground() is calling first and after that only for it will call userNotificationCenter() so I setup the source in this in and after delay of 4 sec uservisited() will gets call
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
SegmentEventData.shared.setUp(appSource: "PN", branchCampaign: "", branchMedium: "")
}
and same case is happening with branch deeplink it will take 3-4 sec to process the data and get to know the deeplink - data present or coming from deeplink .
Branch.getInstance().initSession(launchOptions: launchOptions) { (params, error) in
SegmentEventData.shared.setUp(appSource: "Branch deeplink", branchCampaign: campaign, branchMedium: medium)
}
So after 4 sec my uservisited() event gets called with the proper source. But this timer is generating some random bug also. I want to remove the timer.
I want to know is there any other way to get the source of app.
Can some one Plz help in this context.
Thanks in advance..
Note - I cann't call event two time or there is no other event to track the source, PM wants to add source in this event only.