Skip to content

mainInstance() Can Crash the Application #667

Closed
@FutureSeth

Description

@FutureSeth

We found ourselves in a state where MixPanel was being torn down before being setup Mixpanel.mainInstance.reset() and it was crashing our production application through an assert. It's understandable that there's an order of operations expected when using your SDK but this should be handled gracefully or provide a way to check if it's safe to call mainInstance.

    open class func mainInstance() -> MixpanelInstance {
        if let instance = MixpanelManager.sharedInstance.getMainInstance() {
            return instance
        } else {
            #if !targetEnvironment(simulator)
            assert(false, "You have to call initialize(token:trackAutomaticEvents:) before calling the main instance, " +
                   "or define a new main instance if removing the main one")
            #endif
            
#if !os(OSX) && !os(watchOS)
            return Mixpanel.initialize(token: "", trackAutomaticEvents: true)
#else
            return Mixpanel.initialize(token: "")
#endif
            
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions