Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Oct 18, 2023
1 parent e33fec0 commit 202d927
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 43 deletions.
20 changes: 15 additions & 5 deletions PostHog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
3AE3FB332991388500AFFC18 /* PostHogQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB322991388500AFFC18 /* PostHogQueue.swift */; };
3AE3FB37299162EA00AFFC18 /* PostHogApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB36299162EA00AFFC18 /* PostHogApi.swift */; };
3AE3FB3B29924CE100AFFC18 /* NSData+PHGGZIP.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB3929924CE100AFFC18 /* NSData+PHGGZIP.m */; };
3AE3FB3D29924E8200AFFC18 /* PostHog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB3C29924E8200AFFC18 /* PostHog.swift */; };
3AE3FB3D29924E8200AFFC18 /* PostHogSDK.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB3C29924E8200AFFC18 /* PostHogSDK.swift */; };
3AE3FB3F29924F4F00AFFC18 /* PostHogConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB3E29924F4F00AFFC18 /* PostHogConfig.swift */; };
3AE3FB432992985A00AFFC18 /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB422992985A00AFFC18 /* Reachability.swift */; };
3AE3FB472992AB0000AFFC18 /* Hedgelog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB462992AB0000AFFC18 /* Hedgelog.swift */; };
Expand Down Expand Up @@ -141,7 +141,7 @@
3AE3FB36299162EA00AFFC18 /* PostHogApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogApi.swift; sourceTree = "<group>"; };
3AE3FB3829924CE100AFFC18 /* NSData+PHGGZIP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+PHGGZIP.h"; sourceTree = "<group>"; };
3AE3FB3929924CE100AFFC18 /* NSData+PHGGZIP.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+PHGGZIP.m"; sourceTree = "<group>"; };
3AE3FB3C29924E8200AFFC18 /* PostHog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHog.swift; sourceTree = "<group>"; };
3AE3FB3C29924E8200AFFC18 /* PostHogSDK.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogSDK.swift; sourceTree = "<group>"; };
3AE3FB3E29924F4F00AFFC18 /* PostHogConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogConfig.swift; sourceTree = "<group>"; };
3AE3FB422992985A00AFFC18 /* Reachability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = "<group>"; };
3AE3FB462992AB0000AFFC18 /* Hedgelog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hedgelog.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -296,7 +296,7 @@
3AA4C09B2988315D006C4731 /* Utils */,
3AE3FB36299162EA00AFFC18 /* PostHogApi.swift */,
3AE3FB322991388500AFFC18 /* PostHogQueue.swift */,
3AE3FB3C29924E8200AFFC18 /* PostHog.swift */,
3AE3FB3C29924E8200AFFC18 /* PostHogSDK.swift */,
3AE3FB3E29924F4F00AFFC18 /* PostHogConfig.swift */,
3AE3FB4D2993D1D600AFFC18 /* PostHogSessionManager.swift */,
3AE3FB48299391DF00AFFC18 /* PostHogStorage.swift */,
Expand Down Expand Up @@ -439,7 +439,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1420;
LastUpgradeCheck = 1420;
LastUpgradeCheck = 1500;
TargetAttributes = {
3AA34CF6296D951A003398F4 = {
CreatedOnToolsVersion = 14.2;
Expand Down Expand Up @@ -555,7 +555,7 @@
6926DA8E2ADD2876005760D2 /* PostHogContext.swift in Sources */,
69261D192AD9673500232EC7 /* PostHogBatchUploadInfo.swift in Sources */,
3A0F108529C9ABB6002C0084 /* ReadWriteLock.swift in Sources */,
3AE3FB3D29924E8200AFFC18 /* PostHog.swift in Sources */,
3AE3FB3D29924E8200AFFC18 /* PostHogSDK.swift in Sources */,
3AE3FB3F29924F4F00AFFC18 /* PostHogConfig.swift in Sources */,
3AE3FB332991388500AFFC18 /* PostHogQueue.swift in Sources */,
3AE3FB3B29924CE100AFFC18 /* NSData+PHGGZIP.m in Sources */,
Expand Down Expand Up @@ -746,6 +746,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -810,6 +811,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -835,12 +837,14 @@
buildSettings = {
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_MODULE_VERIFIER = YES;
EXCLUDED_ARCHS = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
Expand All @@ -853,6 +857,8 @@
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20";
PRODUCT_BUNDLE_IDENTIFIER = com.posthog.PostHog;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand All @@ -873,12 +879,14 @@
buildSettings = {
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_MODULE_VERIFIER = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -890,6 +898,8 @@
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20";
PRODUCT_BUNDLE_IDENTIFIER = com.posthog.PostHog;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
2 changes: 1 addition & 1 deletion PostHog.xcodeproj/xcshareddata/xcschemes/PostHog.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
24 changes: 22 additions & 2 deletions PostHog.xcodeproj/xcshareddata/xcschemes/PostHogTests.xcscheme
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
LastUpgradeVersion = "1500"
version = "2.2">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<AutocreatedTestPlanReference>
</AutocreatedTestPlanReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
Expand Down Expand Up @@ -43,6 +54,15 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3AC745BE296D6FE60025C109"
BuildableName = "PostHogTests.xctest"
BlueprintName = "PostHogTests"
ReferencedContainer = "container:PostHog.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
2 changes: 2 additions & 0 deletions PostHog/PostHog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@


#import <Foundation/Foundation.h>
// do not use <>
// 'NSData+PHGGZIP.h' file not found with <angled> include; use "quotes" instead
#import "NSData+PHGGZIP.h"

//! Project version number for PostHog.
Expand Down
2 changes: 1 addition & 1 deletion PostHog/PostHogExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Foundation

*/

public extension PostHog {
public extension PostHogSDK {
static let didStartNotification = Notification.Name("PostHogDidStart") // object: nil
static let didStartRecordingNotification = Notification.Name("PostHogDidStartRecording") // object: nil
static let didResetSessionNotification = Notification.Name("PostHogDidResetSession") // object: String
Expand Down
2 changes: 1 addition & 1 deletion PostHog/PostHogFeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PostHogFeatureFlags {
}

DispatchQueue.main.async {
NotificationCenter.default.post(name: PostHog.didReceiveFeatureFlags, object: nil)
NotificationCenter.default.post(name: PostHogSDK.didReceiveFeatureFlags, object: nil)
}

self.setLoading(false)
Expand Down
19 changes: 10 additions & 9 deletions PostHog/PostHog.swift → PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import Foundation
let retryDelay = 5.0
let maxRetryDelay = 30.0

@objc public class PostHog: NSObject {
// renamed to PostHogSDK due to https://github.com/apple/swift/issues/56573
@objc public class PostHogSDK: NSObject {
private var config: PostHogConfig

private init(_ config: PostHogConfig) {
Expand All @@ -37,8 +38,8 @@ let maxRetryDelay = 30.0
private var context: PostHogContext?
private static var apiKeys = Set<String>()

@objc public static let shared: PostHog = {
let instance = PostHog(PostHogConfig(apiKey: ""))
@objc public static let shared: PostHogSDK = {
let instance = PostHogSDK(PostHogConfig(apiKey: ""))
return instance
}()

Expand All @@ -61,10 +62,10 @@ let maxRetryDelay = 30.0
return
}

if PostHog.apiKeys.contains(config.apiKey) {
if PostHogSDK.apiKeys.contains(config.apiKey) {
hedgeLog("API Key: ${config.apiKey} already has a PostHog instance.")
} else {
PostHog.apiKeys.insert(config.apiKey)
PostHogSDK.apiKeys.insert(config.apiKey)
}

enabled = true
Expand Down Expand Up @@ -95,7 +96,7 @@ let maxRetryDelay = 30.0
queue?.start()

DispatchQueue.main.async {
NotificationCenter.default.post(name: PostHog.didStartNotification, object: nil)
NotificationCenter.default.post(name: PostHogSDK.didStartNotification, object: nil)
}

if config.preloadFeatureFlags {
Expand Down Expand Up @@ -495,7 +496,7 @@ let maxRetryDelay = 30.0

setupLock.withLock {
enabled = false
PostHog.apiKeys.remove(config.apiKey)
PostHogSDK.apiKeys.remove(config.apiKey)

queue?.stop()
queue = nil
Expand All @@ -509,8 +510,8 @@ let maxRetryDelay = 30.0
}
}

@objc public static func with(_ config: PostHogConfig) -> PostHog {
let postHog = PostHog(config)
@objc public static func with(_ config: PostHogConfig) -> PostHogSDK {
let postHog = PostHogSDK(config)
postHog.setup(config)
return postHog
}
Expand Down
2 changes: 1 addition & 1 deletion PostHog/PostHogSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PostHogSessionManager {

hedgeLog("Session expired - creating new session '\(sessionId!)'")
DispatchQueue.main.async {
NotificationCenter.default.post(name: PostHog.didResetSessionNotification, object: sessionId)
NotificationCenter.default.post(name: PostHogSDK.didResetSessionNotification, object: sessionId)
}
}

Expand Down
2 changes: 1 addition & 1 deletion PostHog/Utils/NSData+PHGGZIP.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#pragma clang diagnostic ignored "-Wcast-qual"

void *_Nullable posthog_libzOpen()
void *_Nullable posthog_libzOpen(void)
{
static void *libz;
static dispatch_once_t onceToken;
Expand Down
5 changes: 4 additions & 1 deletion PostHogExample/Api.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ class Api: ObservableObject {

logger.info("Requesting protected endpoint...")
let task = URLSession.shared.dataTask(with: url) { data, _, _ in
print("Response", data)
if data == nil {
return
}
print("Response", String(decoding: data!, as: UTF8.self))
}

task.resume()
Expand Down
6 changes: 3 additions & 3 deletions PostHogExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class AppDelegate: NSObject, UIApplicationDelegate {
apiKey: "_6SG-F7I1vCuZ-HdJL3VZQqjBlaSb1_20hDPwqMNnGI"
)

PostHog.shared.setup(config)
PostHog.shared.debug()
PostHog.shared.capture("App started!")
PostHogSDK.shared.setup(config)
PostHogSDK.shared.debug()
PostHogSDK.shared.capture("App started!")

// DispatchQueue.global(qos: .utility).async {
// let task = Api().failingRequest()
Expand Down
19 changes: 12 additions & 7 deletions PostHogExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class SignInViewModel: NSObject, ObservableObject, ASWebAuthenticationPresentati

// Initialize the session.
let session = ASWebAuthenticationSession(url: authURL, callbackURLScheme: scheme) { callbackURL, error in
print(callbackURL, error)
if callbackURL != nil {
print("URL", callbackURL!.absoluteString)
}
if error != nil {
print("Error", error!.localizedDescription)
}
}
session.presentationContextProvider = self
session.prefersEphemeralWebBrowserSession = true
Expand All @@ -38,19 +43,19 @@ class FeatureFlagsModel: ObservableObject {
@Published var isReloading: Bool = false

init() {
NotificationCenter.default.addObserver(self, selector: #selector(reloaded), name: PostHog.didReceiveFeatureFlags, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(reloaded), name: PostHogSDK.didReceiveFeatureFlags, object: nil)
}

@objc func reloaded() {
boolValue = PostHog.shared.isFeatureEnabled("4535-funnel-bar-viz")
stringValue = PostHog.shared.getFeatureFlag("multivariant") as? String
payloadValue = PostHog.shared.getFeatureFlagPayload("multivariant") as? [String: String]
boolValue = PostHogSDK.shared.isFeatureEnabled("4535-funnel-bar-viz")
stringValue = PostHogSDK.shared.getFeatureFlag("multivariant") as? String
payloadValue = PostHogSDK.shared.getFeatureFlagPayload("multivariant") as? [String: String]
}

func reload() {
isReloading = true

PostHog.shared.reloadFeatureFlags { _, _ in
PostHogSDK.shared.reloadFeatureFlags { _, _ in
self.isReloading = false
}
}
Expand All @@ -71,7 +76,7 @@ struct ContentView: View {
}

func triggerIdentify() {
PostHog.shared.identify(name, userProperties: [
PostHogSDK.shared.identify(name, userProperties: [
"name": name,
])
}
Expand Down
2 changes: 1 addition & 1 deletion PostHogTests/CaptureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Quick
class CaptureTest: QuickSpec {
override func spec() {
var harness: TestPostHog!
var posthog: PostHog!
var posthog: PostHogSDK!

beforeEach {
harness = TestPostHog()
Expand Down
2 changes: 1 addition & 1 deletion PostHogTests/FeatureFlagsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Quick
class FeatureFlagTests: QuickSpec {
override func spec() {
var harness: TestPostHog!
var posthog: PostHog!
var posthog: PostHogSDK!

beforeEach {
harness = TestPostHog()
Expand Down
4 changes: 2 additions & 2 deletions PostHogTests/PostHogTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Quick
class PostHogTest: QuickSpec {
override func spec() {
var harness: TestPostHog!
var posthog: PostHog!
var posthog: PostHogSDK!

beforeEach {
harness = TestPostHog()
Expand Down Expand Up @@ -46,7 +46,7 @@ class PostHogTest: QuickSpec {
let sessionId = posthog.getSessionId()

let config = PostHogConfig(apiKey: "test-api-key")
let otherPostHog = PostHog.with(config)
let otherPostHog = PostHogSDK.with(config)

let otherAnonymousId = otherPostHog.getAnonymousId()
let otherDistinctId = otherPostHog.getDistinctId()
Expand Down
Loading

0 comments on commit 202d927

Please sign in to comment.