TelemetryDeck / SwiftSDK

Swift SDK for TelemetryDeck, a privacy-conscious analytics service for apps and websites.
https://telemetrydeck.com/
Other
149 stars 30 forks source link

[iOS] "newSessionBegan" is not tracked on app launch for older apps without `SceneDelegate` #113

Closed dreymonde closed 1 month ago

dreymonde commented 10 months ago

Quoting the code:

    /// If `true`, sends a "newSessionBegan" Signal on each app foreground or cold launch
    ///
    /// Defaults to true. Set to false to prevent automatically sending this signal.
    public var sendNewSessionBeganSignal: Bool = true

It relies on UIApplication.willEnterForegroundNotification, and, for some reason, allegedly since iOS 14 for apps that do not support SceneDelegate, this notification is not fired on launch, puzzlingly. And considering that there are still many such apps like it out there, I think this should be addressed.

I've made a simple minimal example project that reproduces this issue. Setting a breakpoint at func processSignal(_ signalType: TelemetrySignalType, for clientUser: String? = nil, floatValue: Double? = nil, with additionalPayload: [String: String] = [:], configuration: TelemetryManagerConfiguration) will quickly show that the event is not being fired

TelemetryDeckNewSessionReproduce.zip

Let me know if you have any questions

dreymonde commented 10 months ago

For additional context: https://stackoverflow.com/questions/65618945/uiapplication-didbecomeactivenotification-not-called-ios-14

winsmith commented 10 months ago

Thanks for this report! I'll look into it!