diff --git a/CHANGELOG.md b/CHANGELOG.md index 8486f8389..fdbf775cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +- chore: add Is Emulator support ([#190](https://github.com/PostHog/posthog-ios/pull/190)) + ## 3.11.0 - 2024-09-11 - chore: add personProfiles support ([#187](https://github.com/PostHog/posthog-ios/pull/187)) diff --git a/PostHog/PostHogContext.swift b/PostHog/PostHogContext.swift index 4f0c9149d..035bcca29 100644 --- a/PostHog/PostHogContext.swift +++ b/PostHog/PostHogContext.swift @@ -42,6 +42,12 @@ class PostHogContext { properties["$device_manufacturer"] = "Apple" properties["$device_model"] = platform() + #if targetEnvironment(simulator) + properties["$is_emulator"] = true + #else + properties["$is_emulator"] = false + #endif + #if os(iOS) || os(tvOS) let device = UIDevice.current // use https://github.com/devicekit/DeviceKit diff --git a/PostHog/PostHogSDK.swift b/PostHog/PostHogSDK.swift index 7d78b77b4..e0d5c06ff 100644 --- a/PostHog/PostHogSDK.swift +++ b/PostHog/PostHogSDK.swift @@ -250,6 +250,7 @@ let maxRetryDelay = 30.0 ) } + @discardableResult private func requirePersonProcessing() -> Bool { if config.personProfiles == .never { hedgeLog("personProfiles is set to `never`. This call will be ignored.") diff --git a/PostHogTests/PostHogContextTest.swift b/PostHogTests/PostHogContextTest.swift index 427506d5c..e29c6c92d 100644 --- a/PostHogTests/PostHogContextTest.swift +++ b/PostHogTests/PostHogContextTest.swift @@ -34,6 +34,7 @@ class PostHogContextTest: QuickSpec { expect(context["$app_version"] as? String) != nil expect(context["$app_build"] as? String) != nil expect(context["$app_namespace"] as? String) == "com.apple.dt.xctest.tool" + expect(context["$is_emulator"] as? Bool) != nil #if os(iOS) || os(tvOS) expect(context["$device_name"] as? String) != nil expect(context["$os_name"] as? String) != nil