diff --git a/CHANGELOG.md b/CHANGELOG.md index fcd7ccdd9..177897124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ - add autocapture support for UIKit ([#224](https://github.com/PostHog/posthog-ios/pull/224)) +## 3.13.3 - 2024-10-25 + +- fix race condition in PostHogFileBackedQueue.deleteFiles ([#218](https://github.com/PostHog/posthog-ios/pull/218)) + +## 3.13.2 - 2024-10-18 + +- add missing capture method for objC with groups overload ([#217](https://github.com/PostHog/posthog-ios/pull/217)) + ## 3.13.1 - 2024-10-16 - add optional distinctId parameter to capture methods ([#216](https://github.com/PostHog/posthog-ios/pull/216)) diff --git a/PostHog.podspec b/PostHog.podspec index f6999130a..b70a331e6 100644 --- a/PostHog.podspec +++ b/PostHog.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "PostHog" - s.version = "3.13.1" + s.version = "3.13.3" s.summary = "The hassle-free way to add posthog to your iOS app." s.description = <<-DESC diff --git a/PostHog/PostHogFileBackedQueue.swift b/PostHog/PostHogFileBackedQueue.swift index 24adf0582..ab9160709 100644 --- a/PostHog/PostHogFileBackedQueue.swift +++ b/PostHog/PostHogFileBackedQueue.swift @@ -100,10 +100,14 @@ class PostHogFileBackedQueue { private func deleteFiles(_ count: Int) { for _ in 0 ..< count { - if items.isEmpty { return } - let removed = items.remove(at: 0) // We always remove from the top of the queue - - deleteSafely(queue.appendingPathComponent(removed)) + if let removed: String = _items.mutate({ items in + if items.isEmpty { + return nil + } + return items.remove(at: 0) // We always remove from the top of the queue + }) { + deleteSafely(queue.appendingPathComponent(removed)) + } } } } diff --git a/PostHog/PostHogSDK.swift b/PostHog/PostHogSDK.swift index 768d7467f..bacc3e66b 100644 --- a/PostHog/PostHogSDK.swift +++ b/PostHog/PostHogSDK.swift @@ -489,7 +489,7 @@ let maxRetryDelay = 30.0 } @objc public func capture(_ event: String) { - capture(event, properties: nil, userProperties: nil, userPropertiesSetOnce: nil, groups: nil) + capture(event, distinctId: nil, properties: nil, userProperties: nil, userPropertiesSetOnce: nil, groups: nil) } @objc(captureWithEvent:properties:) @@ -524,6 +524,16 @@ let maxRetryDelay = 30.0 return false } + @objc(captureWithEvent:properties:userProperties:userPropertiesSetOnce:groups:) + public func capture(_ event: String, + properties: [String: Any]? = nil, + userProperties: [String: Any]? = nil, + userPropertiesSetOnce: [String: Any]? = nil, + groups: [String: String]? = nil) + { + capture(event, distinctId: nil, properties: properties, userProperties: userProperties, userPropertiesSetOnce: userPropertiesSetOnce, groups: groups) + } + @objc(captureWithEvent:distinctId:properties:userProperties:userPropertiesSetOnce:groups:) public func capture(_ event: String, distinctId: String? = nil, diff --git a/PostHog/PostHogVersion.swift b/PostHog/PostHogVersion.swift index fdfa2b270..fa42f2d51 100644 --- a/PostHog/PostHogVersion.swift +++ b/PostHog/PostHogVersion.swift @@ -9,7 +9,7 @@ import Foundation // if you change this, make sure to also change it in the podspec and check if the script scripts/bump-version.sh still works // This property is internal only -public var postHogVersion = "3.13.1" +public var postHogVersion = "3.13.3" // This property is internal only public var postHogSdkName = "posthog-ios" diff --git a/PostHog/Utils/ReadWriteLock.swift b/PostHog/Utils/ReadWriteLock.swift index cd7d05934..c782a15f0 100644 --- a/PostHog/Utils/ReadWriteLock.swift +++ b/PostHog/Utils/ReadWriteLock.swift @@ -50,10 +50,13 @@ public final class ReadWriteLock { /// The lock will be acquired once for writing before invoking the closure. /// /// - Parameter closure: The closure with the mutable value. - public func mutate(_ closure: (inout Value) -> Void) { + @discardableResult + public func mutate(_ closure: (inout Value) -> T) -> T { pthread_rwlock_wrlock(&rwlock) - closure(&value) - pthread_rwlock_unlock(&rwlock) + defer { + pthread_rwlock_unlock(&rwlock) + } + return closure(&value) } }