Skip to content

Commit

Permalink
feat: add sample xcframework project
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannisj committed Jan 28, 2025
1 parent e46243e commit 0e8610c
Show file tree
Hide file tree
Showing 16 changed files with 1,198 additions and 27 deletions.
61 changes: 34 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ buildSdk:
set -o pipefail && xcrun xcodebuild clean build -scheme PostHog -destination generic/platform=watchos | xcpretty #watchOS
set -o pipefail && xcrun xcodebuild clean build -scheme PostHog -destination 'platform=visionOS Simulator,name=Apple Vision Pro' | xcpretty #visionOS

buildExamples:
set -o pipefail && xcrun xcodebuild -downloadAllPlatforms
buildExamples: \
buildExamplesPlatforms \
buildExampleXCFramework \
buildExamplePodsDynamic \
buildExamplePodsStatic \

buildExamplesPlatforms:
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExample -destination generic/platform=ios | xcpretty #ios
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExample -destination 'platform=visionOS Simulator,name=Apple Vision Pro' | xcpretty #visionOS
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogObjCExample -destination generic/platform=ios | xcpretty #ObjC
Expand All @@ -21,33 +26,35 @@ buildExamples:
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExampleTvOS -destination generic/platform=tvos | xcpretty #watchOS
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExampleWithSPM -destination generic/platform=ios | xcpretty #SPM

## Build with dynamic framework
cd PostHogExampleWithPods && \
pod install && \
cd .. && \
xcrun xcodebuild clean build \
-workspace PostHogExampleWithPods/PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios | xcpretty

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

buildExamplePodsStatic:
cd PostHogExampleWithPods && \
cp Podfile{,.backup} && \
cp Podfile.static Podfile && \
cp PostHogExampleWithPods.xcodeproj/project.pbxproj{,.backup} && \
pod install && \
cd .. && \
xcrun xcodebuild clean build \
-workspace PostHogExampleWithPods/PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios | xcpretty

## Restore original files
cp Podfile{,.backup} && \
cp Podfile.static Podfile && \
cp PostHogExampleWithPods.xcodeproj/project.pbxproj{,.backup} && \
pod install && \
cd .. && \
set -o pipefail && xcrun xcodebuild clean build \
-workspace PostHogExampleWithPods/PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios | xcpretty && \
cd PostHogExampleWithPods && \
mv Podfile{.backup,} && \
pod install && \
mv PostHogExampleWithPods.xcodeproj/project.pbxproj{.backup,}

mv Podfile{.backup,} && \
pod install && \
mv PostHogExampleWithPods.xcodeproj/project.pbxproj{.backup,}

buildExampleXCFramework:
./PostHogExampleExternalSDK/build_xcframework.sh
set -o pipefail && xcrun xcodebuild clean build \
-project ./PostHogExampleExternalSDK/SDKClient/PostHogExampleExternalSDKClient.xcodeproj \
-scheme ExternalSDKClient \
-destination "generic/platform=iOS Simulator" | xcpretty

format: swiftLint swiftFormat

Expand Down
34 changes: 34 additions & 0 deletions PostHogExampleExternalSDK/ExternalSDK.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// ExternalSDK.swift
// ExternalSDK
//
// Created by Yiannis Josephides on 24/01/2025.
//

import Foundation
import PostHog

public final class MyExternalSDK {
public static let shared = MyExternalSDK()

private init() {
let config = PostHogConfig(
apiKey: "phc_QFbR1y41s5sxnNTZoyKG2NJo2RlsCIWkUfdpawgb40D"
)

config.captureScreenViews = true
config.captureApplicationLifecycleEvents = true
config.debug = true
config.sendFeatureFlagEvent = false
config.sessionReplay = true
config.sessionReplayConfig.maskAllImages = false
config.sessionReplayConfig.maskAllTextInputs = false
config.sessionReplayConfig.maskAllSandboxedViews = false

PostHogSDK.shared.setup(config)
}

public func track(event: String) {
PostHogSDK.shared.capture("An Event From ExternalSDK - \(event)")
}
}
18 changes: 18 additions & 0 deletions PostHogExampleExternalSDK/ExternalSDK/ExternalSDK.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ExternalSDK.h
// ExternalSDK
//
// Created by Yiannis Josephides on 23/01/2025.
//

#import <Foundation/Foundation.h>

//! Project version number for ExternalSDK.
FOUNDATION_EXPORT double ExternalSDKVersionNumber;

//! Project version string for TestBuildIssues.
FOUNDATION_EXPORT const unsigned char ExternalSDKVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <TestBuildIssues/PublicHeader.h>


28 changes: 28 additions & 0 deletions PostHogExampleExternalSDK/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ExternalSDK",
platforms: [.iOS(.v15)],
products: [
.library(
name: "ExternalSDK",
targets: ["ExternalSDK-iOS"]
),
],
dependencies: [
.package(path: "../"),
],
targets: [
.target(
name: "ExternalSDK-iOS",
dependencies: [
.product(name: "PostHog", package: "posthog-ios"),
.target(name: "ExternalSDK"),
]
),
.binaryTarget(name: "ExternalSDK", path: "./build/bin/ExternalSDK.xcframework"),
]
)
Loading

0 comments on commit 0e8610c

Please sign in to comment.