analytics-ios
analytics-ios copied to clipboard
Automatically collected lifecycle events not SwiftUI friendly
Platform:
iOS + tvOS
Problem:
Segment auto tracked lifecycles events do not function with the SwiftUI lifecycle. Segment initialization requires UIApplication
be valid to set up notification observers of global events such as: UIApplicationWillEnterForegroundNotification
.
UIApplication
instance is not available on init
of SwiftUI lifecycle @main
. To workaround this, the app delegate adaptor for UIKit lifecycle hooks must be implemented and Segment must be initialized in applicationDidFinishLaunching
.
This is not documented by Segment and can easily go unnoticed until it is realized that the auto tracked lifecycle events are not being fired.
My suggestion is that Segment not require UIApplication
to be valid for setting up notification observers of global events for auto tracked lifecycle events.
Hi @loganblevins I have app with SwiftUI facing same issue trackApplicationLifecycleEvents is not working in app
any suggestion how to fix that
Platform:
iOS : SwiftUI
I configured everything as per SDK documents TrackApplicationLifecycleEvents = true as well
But Application Opened, Application Installed, Application Updated is not functional in app
Any special things need to configure for this for SwiftUI to work on this event.
I would also comment that this is more than just an minor documentation issue, since it is very likely that the app will be doing things during App
initialization (like identifying the user) that requires that Segment has already been initialized. So if we have to wait for AppDelete didFinishLaunching to initialize Segment, then those attempts to do anything will crash.
We ended up just doing our own lifecycle tracking and turned off Segment's for now.