Skip to content
Merged
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 .changeset/v4-major-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PostHog iOS 4.0. Every breaking change below names what to use instead.

**Changed**

- **Breaking:** stop publishing PostHog to CocoaPods: install it with Swift Package Manager (3.x versions stay on CocoaPods).
- **Breaking:** raise the minimum deployment targets to iOS 15.0 (from 13.0, Mac Catalyst follows iOS), macOS 11.0 (from 10.15), tvOS 15.0 (from 13.0) and watchOS 10.0 (from 6.0).
- **Breaking:** require Xcode 26 or later (`swift-tools-version` 6.2) to build PostHog; the SDK still compiles in Swift 5 language mode.
- **Breaking:** pass a `PostHogFeatureFlagsLoaded` to the `reloadFeatureFlags(_:)` callback, whose `errorsLoading` is `true` when the reload failed. Update closures to `{ result in ... }` (or `{ _ in ... }`); in Objective-C the block takes a `PostHogFeatureFlagsLoaded *`.
Expand Down
31 changes: 0 additions & 31 deletions .github/workflows/build-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,3 @@ jobs:
xcode-version: latest-stable
- name: Build XCFramework Example
run: make buildExampleXCFramework

build-pods:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- name: Static Lib
target: buildExamplePodsStaticLib
runner: macos-15
xcode-version: latest-stable
- name: Static Lib (Xcode 26.0.1)
target: buildExamplePodsStaticLib
runner: macos-15-xlarge
xcode-version: '26.0.1'
- name: Static Framework
target: buildExamplePodsStaticFramework
runner: macos-15
xcode-version: latest-stable
- name: Dynamic Framework
target: buildExamplePodsDynamicFramework
runner: macos-15
xcode-version: latest-stable
name: Example Pods (${{ matrix.name }})
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1.7.0
with:
xcode-version: ${{ matrix.xcode-version }}
- name: Build Pods Example (${{ matrix.name }})
run: make ${{ matrix.target }}
33 changes: 0 additions & 33 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,36 +92,3 @@ jobs:
- name: Build SDK via Swift Package Manager with package traits off
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
run: make buildSdkSpmNoTraits
- name: Install CocoaPods
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
run: gem install cocoapods
- name: Install Pods
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
run: |
cd PostHogExampleWithPods
USE_FRAMEWORKS=static pod install
- name: Build SDK with Swift 5 language mode via CocoaPods
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
run: |
set -o pipefail
cd PostHogExampleWithPods
xcrun xcodebuild clean build \
-workspace PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios \
SWIFT_VERSION=5 | xcpretty

podspec-lint:
needs: detect-markdown-only
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
runs-on: macos-15
name: CocoaPods package lint
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1.7.0
with:
xcode-version: latest-stable
- name: Install CocoaPods
run: gem install cocoapods
- name: Lint podspec
run: pod lib lint PostHog.podspec --allow-warnings --skip-tests
94 changes: 2 additions & 92 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ jobs:
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "Version to release: $NEW_VERSION"

# Tag must be pushed to remote before CocoaPods publish, because
# `pod trunk push` validates by cloning the repo at this tag from GitHub.
- name: Tag and push to GitHub
env:
RELEASE_VERSION: ${{ steps.get-version.outputs.version }}
Expand Down Expand Up @@ -294,99 +292,11 @@ jobs:
message: '❌ Failed to create the GitHub release for `posthog-ios@v${{ steps.get-version.outputs.version }}`! <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>'
emoji_reaction: 'x'

publish-cocoapods:
name: Publish to CocoaPods
needs: [create-github-release, notify-approval-needed]
runs-on: macos-15
if: always() && needs.create-github-release.result == 'success'
permissions:
contents: read
env:
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} # Using @ioannisj token
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.create-github-release.outputs.version }}
fetch-depth: 0

- uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1.7.0
with:
xcode-version: '26.0.1'

- name: Publish to CocoaPods
env:
RELEASE_VERSION: ${{ needs.create-github-release.outputs.version }}
run: |
set -euo pipefail

on_trunk() {
pod trunk info PostHog --no-ansi 2>/dev/null \
| grep -E -- "^[[:space:]]*- ${RELEASE_VERSION//./\\.} \("
}

if make releaseCocoaPods; then
exit 0
fi

# `pod trunk push` regularly exits non-zero *after* the spec is already
# accepted (its final CDN/response verification times out). Trunk
# registration and the `pod trunk info` endpoint can lag a bit and the
# info call itself is occasionally flaky, so poll rather than check once.
echo "::warning::pod trunk push failed. Polling pod trunk info to confirm the version landed..."
for attempt in $(seq 1 10); do
if on_trunk; then
echo "PostHog $RELEASE_VERSION is on trunk (attempt $attempt/10). Treating as success."
exit 0
fi
if [ "$attempt" -lt 10 ]; then
echo "Not visible yet (attempt $attempt/10); retrying in 30s..."
sleep 30
fi
done

echo "::error::PostHog $RELEASE_VERSION is not on trunk after polling for ~5 minutes."
exit 1

# Notify in case of failure
- name: Send failure event to PostHog
if: ${{ failure() }}
continue-on-error: true
uses: PostHog/posthog-github-action@9a6a19d360820ab4d95ecc4a5a7564062c895f84 # v1.3.0
with:
posthog-token: '${{ secrets.POSTHOG_PROJECT_API_KEY }}'
event: 'posthog-sdk-github-release-workflow-failure'
properties: >-
{
"commitSha": "${{ github.sha }}",
"jobStatus": "${{ job.status }}",
"ref": "${{ github.ref }}",
"repository": "${{ github.repository }}",
"sdk": "posthog-ios",
"jobName": "publish-cocoapods",
"packageName": "posthog-ios",
"packageVersion": "${{ needs.create-github-release.outputs.version || 'unknown' }}",
"actionUrl": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"alertText": ":rotating_light: Failed to publish posthog-ios@v${{ needs.create-github-release.outputs.version }} to CocoaPods :rotating_light:",
"alertContext": "The CocoaPods publish step failed."
}

- name: Notify Slack - Failed
continue-on-error: true
if: ${{ failure() && needs.notify-approval-needed.outputs.slack_ts != '' }}
uses: PostHog/.github/.github/actions/slack-thread-reply@cb0979b67dcd585828b61ac45927eef4da8f6287 # main
with:
slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }}
slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }}
thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }}
message: '❌ Failed to publish `posthog-ios@v${{ needs.create-github-release.outputs.version }}` to CocoaPods! <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>'
emoji_reaction: 'x'

notify-released:
name: Notify Slack - Released
needs: [notify-approval-needed, publish-cocoapods]
needs: [notify-approval-needed, create-github-release]
runs-on: ubuntu-latest
if: always() && needs.publish-cocoapods.result == 'success' && needs.notify-approval-needed.outputs.slack_ts != ''
if: always() && needs.create-github-release.result == 'success' && needs.notify-approval-needed.outputs.slack_ts != ''
steps:
- name: Notify Slack - Released
continue-on-error: true
Expand Down
1 change: 0 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ excluded: # case-sensitive paths to ignore during linting. Takes precedence over
- PostHogExampleWatchOS
- PostHogExampleWidget
- PostHogExampleWidgetAppGroup
- PostHogExampleWithPods
- PostHogExampleWithSPM
- PostHogTests
- PostHogSurveyUITests
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Repository invariants
- Maintain Swift 5 SDK language mode. The package needs swift-tools-version 6.2 (Xcode 26+); prefer Swift Testing for new tests. Use `PostHogTests/TestUtils/MockPostHogServer.swift` for HTTP stubbing.
- Preserve deployment minima: iOS 15, tvOS 15, macOS 11, watchOS 10, visionOS 1. Keep platform guards and graceful degradation, especially for session replay. Availability annotations/checks do not require adding platform support or raising targets. Intentional support changes require checking `Package.swift` plus CocoaPods/Xcode packaging/build configuration.
- Preserve deployment minima: iOS 15, tvOS 15, macOS 11, watchOS 10, visionOS 1. Keep platform guards and graceful degradation, especially for session replay. Availability annotations/checks do not require adding platform support or raising targets. Intentional support changes require checking `Package.swift` plus the Xcode project build configuration.
- Public APIs must remain thread-safe and callable from any thread. Preserve offline operation and queue-based event batching; never assume connectivity. `PostHogSDK.shared` is the default singleton; independent instances use `PostHogSDK.with(_:)` with `PostHogConfig`.
- Preserve replay masking/privacy behavior and privacy-safe error logging; do not expose sensitive user data.
- Prefer no new dependencies. libwebp is embedded; PHPLCrashReporter is vendored, prefixed PLCrashReporter for native crash reporting on iOS/macOS/tvOS, excluded on watchOS/visionOS. Both are behind default-on package traits (`SessionReplay`, which also gates the replay engine, and `CrashReporting`); gate code that uses them with `#if !SWIFT_PACKAGE || <Trait>`. The survey engine and UI are behind the default-on `Surveys` trait the same way. Once released, never add a new default-on trait on its own: apps that list traits would silently lose the feature. Split an existing trait instead, keeping it as an umbrella that enables the new ones.
Expand Down
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This repo requires all commits to be signed. To configure commit signing, see th

Use the repository's `make` wrappers rather than invoking `swift` or `xcodebuild` directly; [Makefile](Makefile) owns the commands and options.

For initial setup, install Xcode 26 or later and, if needed, use `make bootstrap` to install CocoaPods, xcpretty, SwiftLint, SwiftFormat and Periphery. Agents should report missing prerequisites rather than install tools without authorization. The package uses swift-tools-version 6.2 and compiles in Swift 5 language mode; use current stable Xcode as CI does.
For initial setup, install Xcode 26 or later and, if needed, use `make bootstrap` to install xcpretty, SwiftLint, SwiftFormat and Periphery. Agents should report missing prerequisites rather than install tools without authorization. The package uses swift-tools-version 6.2 and compiles in Swift 5 language mode; use current stable Xcode as CI does.

Iterate with focused checks, then run the core CI-aligned checks before submitting **SDK changes**:

Expand Down Expand Up @@ -43,10 +43,9 @@ Markdown-only changes need documentation/link checks and `git diff --check`, not
| SDK across supported platforms, including Mac Catalyst | `make buildSdk` |
| Code gated by the `SessionReplay`, `CrashReporting` or `Surveys` package traits | `make buildSdkSpmNoTraits`, `make testNoTraits`, `make buildTestsSpmTraitsIOS` |
| Example/platform integrations | `make buildExamplesPlatforms` |
| CocoaPods integration modes | `make buildExamplePodsStaticLib`, `make buildExamplePodsStaticFramework`, `make buildExamplePodsDynamicFramework` |
| XCFramework integration | `make buildExampleXCFramework` |

Use relevant example/package checks for integration or packaging changes, and smoke test changed behavior in an example where applicable. `make buildExamples` runs all example builds; `make build` combines that with `make buildSdk`. These broad targets include CocoaPods installation and XCFramework generation, so they are not the default iteration loop. For package/support changes, also consult the package lint and minimum-toolchain lanes in [build CI](.github/workflows/build.yml) and [example CI](.github/workflows/build-examples.yml).
Use relevant example/package checks for integration or packaging changes, and smoke test changed behavior in an example where applicable. `make buildExamples` runs all example builds; `make build` combines that with `make buildSdk`. These broad targets include XCFramework generation, so they are not the default iteration loop. For package/support changes, also consult the public API and minimum-toolchain lanes in [build CI](.github/workflows/build.yml) and [example CI](.github/workflows/build-examples.yml).

### Simulator, UI and masking prerequisites

Expand Down
44 changes: 1 addition & 43 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: testSurveyUI build buildSdk buildExamples format swiftLint swiftFormat swiftLintCheck swiftFormatCheck installSwiftLint installSwiftFormat test testUploadSymbols recordEventShapeSnapshots testDowngradeCompatibility checkTestRegistration testOniOSSimulator testOnMacSimulator maskSnapshots recordMaskSnapshots checkMaskSnapshotRuntime lint bootstrap releaseCocoaPods api apiCheck apiUpdate buildIOS buildSdkSpm buildSdkSpmNoTraits buildTestsSpmTraitsIOS testNoTraits
.PHONY: testSurveyUI build buildSdk buildExamples format swiftLint swiftFormat swiftLintCheck swiftFormatCheck installSwiftLint installSwiftFormat test testUploadSymbols recordEventShapeSnapshots testDowngradeCompatibility checkTestRegistration testOniOSSimulator testOnMacSimulator maskSnapshots recordMaskSnapshots checkMaskSnapshotRuntime lint bootstrap api apiCheck apiUpdate buildIOS buildSdkSpm buildSdkSpmNoTraits buildTestsSpmTraitsIOS testNoTraits

build: buildSdk buildExamples

Expand Down Expand Up @@ -35,12 +35,6 @@ buildTestsSpmTraitsIOS:
buildExamples: \
buildExamplesPlatforms \
buildExampleXCFramework \
buildExamplePods \

buildExamplePods: \
buildExamplePodsStaticLib \
buildExamplePodsStaticFramework \
buildExamplePodsDynamicFramework \

buildExamplesPlatforms:
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExample -destination generic/platform=ios | xcpretty #ios
Expand All @@ -54,30 +48,6 @@ buildExamplesPlatforms:
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExampleStoryboard -destination generic/platform=ios | xcpretty #Storyboard
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExampleWithSPM -destination 'platform=macOS,variant=Mac Catalyst' | xcpretty #Mac Catalyst SPM

buildExamplePodsDynamicFramework:
cd PostHogExampleWithPods && \
USE_FRAMEWORKS=dynamic pod install && cd .. && \
set -o pipefail && xcrun xcodebuild clean build \
-workspace PostHogExampleWithPods/PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios | xcpretty

buildExamplePodsStaticFramework:
cd PostHogExampleWithPods && \
USE_FRAMEWORKS=static pod install && cd .. && \
set -o pipefail && xcrun xcodebuild clean build \
-workspace PostHogExampleWithPods/PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios | xcpretty

buildExamplePodsStaticLib:
cd PostHogExampleWithPods && \
pod install && cd .. && \
set -o pipefail && xcrun xcodebuild clean archive \
-workspace PostHogExampleWithPods/PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios | xcpretty

buildExampleXCFramework:
./PostHogExampleExternalSDK/build_xcframework.sh
set -o pipefail && xcrun xcodebuild clean build \
Expand Down Expand Up @@ -251,19 +221,7 @@ apiUpdate:
# requires gem and brew
# xcpretty needs 'export LANG=en_US.UTF-8'
bootstrap:
gem install cocoapods
gem install xcpretty
brew install swiftlint
brew install swiftformat
brew install peripheryapp/periphery/periphery

# download SDKs and runtimes
# create Apple Vision Pro simulator if missing
# release pod
releaseCocoaPods:
set -o pipefail && xcrun xcodebuild -downloadAllPlatforms
@if ! xcrun simctl list devices | grep -q "Apple Vision Pro"; then \
LATEST_RUNTIME=$$(xcrun simctl list runtimes | grep "com.apple.CoreSimulator.SimRuntime.xrOS" | sort -r | head -n 1 | awk '{print $$NF}') && \
xcrun simctl create "Apple Vision Pro" "Apple Vision Pro" "$$LATEST_RUNTIME"; \
fi
pod trunk push PostHog.podspec --allow-warnings
Loading
Loading