PostHog / posthog-ios

PostHog iOS SDK
https://posthog.com/docs/libraries/ios
MIT License
32 stars 41 forks source link

Crash: `[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: $anon_distinct_id)'` #35

Closed karolkulesza closed 10 months ago

karolkulesza commented 1 year ago

Steps to reproduce:

  1. Create a new empty app Xcode project and add posthog-ios lib v.2.0.0
  2. Add the following code in in ViewController and invoke testPostHogReset() method in ViewController's viewDidLoad method (updating the value of apiKey in setupPostHog method)
  3. Build & run and wait for the crash
var client: PHGPostHog?

func testPostHogReset() {
    setupPostHog()
    identifyAndGroup()
    DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
      self.client?.reset()
      DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
        self.identifyAndGroup()
      }
    }
  }

  func setupPostHog() {
    let apiKey = "..."
    let hostString = "https://eu.posthog.com"
    let configuration = PHGPostHogConfiguration(apiKey: apiKey, host: hostString)
    configuration.captureApplicationLifecycleEvents = true

    PHGPostHog.setup(with: configuration)
    client = PHGPostHog.shared()
  }

  func identifyAndGroup() {
    client?.identify("test_user")
    client?.group("project", groupKey: "Test Project")
  }
EDsCODE commented 1 year ago

Hello! Thanks for the heads up. Looking into this

karolkulesza commented 1 year ago

Thanks @EDsCODE , I can see that the fix for this issue was already merged to master. Do you know when it'll be available via SPM ?

marandaneto commented 10 months ago

Already fixed