Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset deletes only sdk files instead of the whole folder #132

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- 3.2.5_patch
pull_request:
paths-ignore:
- "**/*.md"
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- 3.2.5_patch
pull_request:
paths-ignore:
- "**/*.md"
Expand All @@ -13,4 +14,6 @@ jobs:
- uses: actions/checkout@v4

- name: Run lints
run: make lint
run: |
brew install swiftlint
make lint
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- 3.2.5_patch
pull_request:
paths-ignore:
- "**/*.md"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Next

## 3.2.5 - 2024-05-14

- fix: `reset` deletes only sdk files instead of the whole folder [#132](https://github.com/PostHog/posthog-ios/pull/132)

## 3.2.4 - 2024-03-12

- `maxQueueSize` wasn't respected when capturing events [#116](https://github.com/PostHog/posthog-ios/pull/116)
Expand Down
2 changes: 1 addition & 1 deletion PostHog.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "PostHog"
s.version = "3.2.4"
s.version = "3.2.5"
s.summary = "The hassle-free way to add posthog to your iOS app."

s.description = <<-DESC
Expand Down
13 changes: 11 additions & 2 deletions PostHog/PostHogStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func applicationSupportDirectoryURL() -> URL {
}

class PostHogStorage {
// when adding or removing items here, make sure to update the reset method
enum StorageKey: String {
case distinctId = "posthog.distinctId"
case anonymousId = "posthog.anonymousId"
Expand Down Expand Up @@ -125,8 +126,16 @@ class PostHogStorage {
}

public func reset() {
deleteSafely(appFolderUrl)
createDirectoryAtURLIfNeeded(url: appFolderUrl)
// sadly the StorageKey.allCases does not work here
deleteSafely(url(forKey: .distinctId))
deleteSafely(url(forKey: .anonymousId))
// .queue not needed since it'll be deleted by the queue.clear()
deleteSafely(url(forKey: .oldQeueue))
deleteSafely(url(forKey: .enabledFeatureFlags))
deleteSafely(url(forKey: .enabledFeatureFlagPayloads))
deleteSafely(url(forKey: .groups))
deleteSafely(url(forKey: .registerProperties))
deleteSafely(url(forKey: .optOut))
}

public func remove(key: StorageKey) {
Expand Down
2 changes: 1 addition & 1 deletion PostHog/PostHogVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.4"
public var postHogVersion = "3.2.5"

// This property is internal only
public var postHogSdkName = "posthog-ios"
1 change: 1 addition & 0 deletions PostHogExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {
PostHogSDK.shared.setup(config)
// PostHogSDK.shared.debug()
// PostHogSDK.shared.capture("App started!")
// PostHogSDK.shared.reset()

let defaultCenter = NotificationCenter.default

Expand Down
12 changes: 12 additions & 0 deletions PostHogTests/PostHogSDKTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,18 @@ class PostHogSDKTest: QuickSpec {
sut.reset()
sut.close()
}

it("reset deletes posthog files but not other folders") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

let appFolder = applicationSupportDirectoryURL()
expect(FileManager.default.fileExists(atPath: appFolder.path)) == false

let sut = self.getSut()

sut.reset()
sut.close()

expect(FileManager.default.fileExists(atPath: appFolder.path)) == true
}
}
}

Expand Down