-
Notifications
You must be signed in to change notification settings - Fork 246
Description
Environment
Xcode Version 13.2.1 (13C100)
Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
SPM Resolved Dependency:
{
"package": "Mixpanel",
"repositoryURL": "https://github.com/mixpanel/mixpanel-swift",
"state": {
"branch": "master",
"revision": "8f6fcb1876f48ef4e7794c66719b23838c990410",
"version": null
}
}Issue
I'm building a SwiftUI iOS app with a min deployment of iOS 14+. Because of this I'm using the SwiftUI types introduced in iOS 14 like App, Scene, etc. As such, I'm not notified that the app has launched through the app or scene delegate as is the case for UIKit apps. With this "pure" SwiftUI approach, all initializations are typically done within the App's init function.
With the initialization of Mixpanel, all of a sudden the project's Global accent color (contained by an Asset Catalog) is reverted to the default system blue.
@main
struct MyApp: App {
init() {
// Initialize Mixpanel
Mixpanel.initialize(token: .mixpanelToken)
#if DEBUG
Mixpanel.mainInstance().loggingEnabled = true
#endif
}
var body: some Scene {
WindowGroup {
MyAppView()
}
}
}I believe this is an issue with the initialization API because when I comment out the line...
// Mixpanel.initialize(token: .mixpanelToken)...the app global accent color works as expected.
What I've tried to remedy the issue
- Changing the Target's Global Accent Color Name & the corresponding
.xcassetitem from the default"AccentColor"to a non-standard name. - Checking the build log to see if other asset catalogs were unexpectedly compiled into the binary
- Forking the repo & updating the Xcode project settings
Current Workaround
I've created a lazily built reference to Mixpanel.mainInstance() in which I initialize the token. This allows the Mixpanel initialize token code to be ran on the first time the app fires off the first track event.
lazy var instance: MixpanelInstance = {
// Mixpanel
Mixpanel.initialize(token: .mixpanelToken)
#if DEBUG
Mixpanel.mainInstance().loggingEnabled = true
#endif
return Mixpanel.mainInstance()
}()This isn't ideal because any tracking associated with initializing Mixpanel is deferred until the first actively tracked event leaving a gap between launch and the first event in unknown territory.
Do you have any idea what's going on here? Thanks!