Detecting organic vs. local notification vs. remote notification app launches
func applicationDidBecomeActive(_ application: UIApplication) { | |
let notificationController = NotificationController.shared | |
// Track app launch if the notificationController didn't already do it | |
if !notificationController.handledLaunchAnalytics { | |
Analytics.trackAppLaunched(source: .Organic) | |
} | |
} |
private(set) var handledLaunchAnalytics: Bool = false | |
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { | |
let atAppLaunch: Bool = (UIApplication.shared.applicationState != .active) | |
let request: UNNotificationRequest = response.notification.request | |
if let trigger = request.trigger, trigger is UNPushNotificationTrigger { | |
// if atAppLaunch == true, call Analytics.trackAppLaunched(source: .remoteNotification) | |
// and flag handledLaunchAnalytics as true | |
// then you can handle your remote notification here | |
} else { | |
// if atAppLaunch == true, call Analytics.trackAppLaunched(source: .localNotification) | |
// and flag handledLaunchAnalytics as true | |
// then you can handle your local notification here | |
} | |
completionHandler() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment