diff --git a/PostHog.xcodeproj/project.pbxproj b/PostHog.xcodeproj/project.pbxproj index 117c689c4..e6d5a564c 100644 --- a/PostHog.xcodeproj/project.pbxproj +++ b/PostHog.xcodeproj/project.pbxproj @@ -54,6 +54,15 @@ 69261D232AD9784200232EC7 /* PostHogVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69261D222AD9784200232EC7 /* PostHogVersion.swift */; }; 69261D252AD9787A00232EC7 /* PostHogExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69261D242AD9787A00232EC7 /* PostHogExtensions.swift */; }; 6926DA8E2ADD2876005760D2 /* PostHogContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6926DA8D2ADD2876005760D2 /* PostHogContext.swift */; }; + 69278D362AE6BC7100BB541A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 69278D352AE6BC7100BB541A /* AppDelegate.m */; }; + 69278D392AE6BC7100BB541A /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 69278D382AE6BC7100BB541A /* SceneDelegate.m */; }; + 69278D3C2AE6BC7100BB541A /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 69278D3B2AE6BC7100BB541A /* ViewController.m */; }; + 69278D3F2AE6BC7100BB541A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 69278D3D2AE6BC7100BB541A /* Main.storyboard */; }; + 69278D412AE6BC7200BB541A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 69278D402AE6BC7200BB541A /* Assets.xcassets */; }; + 69278D442AE6BC7200BB541A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 69278D422AE6BC7200BB541A /* LaunchScreen.storyboard */; }; + 69278D472AE6BC7200BB541A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 69278D462AE6BC7200BB541A /* main.m */; }; + 69278D4B2AE6BC9000BB541A /* PostHog.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AC745B5296D6FE60025C109 /* PostHog.framework */; }; + 69278D4C2AE6BC9000BB541A /* PostHog.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3AC745B5296D6FE60025C109 /* PostHog.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 69779BEC2AE68E6900D7A48E /* UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69779BEB2AE68E6900D7A48E /* UIViewController.swift */; }; /* End PBXBuildFile section */ @@ -79,6 +88,13 @@ remoteGlobalIDString = 3AC745B4296D6FE60025C109; remoteInfo = PostHog; }; + 69278D4D2AE6BC9000BB541A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 3AC745AC296D6FE60025C109 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 3AC745B4296D6FE60025C109; + remoteInfo = PostHog; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -93,6 +109,17 @@ name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; }; + 69278D4F2AE6BC9000BB541A /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 69278D4C2AE6BC9000BB541A /* PostHog.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ @@ -141,6 +168,18 @@ 69261D222AD9784200232EC7 /* PostHogVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogVersion.swift; sourceTree = ""; }; 69261D242AD9787A00232EC7 /* PostHogExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogExtensions.swift; sourceTree = ""; }; 6926DA8D2ADD2876005760D2 /* PostHogContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogContext.swift; sourceTree = ""; }; + 69278D322AE6BC7100BB541A /* PostHogObjCExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PostHogObjCExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 69278D342AE6BC7100BB541A /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 69278D352AE6BC7100BB541A /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 69278D372AE6BC7100BB541A /* SceneDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SceneDelegate.h; sourceTree = ""; }; + 69278D382AE6BC7100BB541A /* SceneDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SceneDelegate.m; sourceTree = ""; }; + 69278D3A2AE6BC7100BB541A /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 69278D3B2AE6BC7100BB541A /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 69278D3E2AE6BC7100BB541A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 69278D402AE6BC7200BB541A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 69278D432AE6BC7200BB541A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 69278D452AE6BC7200BB541A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 69278D462AE6BC7200BB541A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 69779BEB2AE68E6900D7A48E /* UIViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -173,6 +212,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 69278D2F2AE6BC7100BB541A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 69278D4B2AE6BC9000BB541A /* PostHog.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -240,6 +287,7 @@ 3AC745B7296D6FE60025C109 /* PostHog */, 3AC745C3296D6FE60025C109 /* PostHogTests */, 3AA34CF8296D951A003398F4 /* PostHogExample */, + 69278D332AE6BC7100BB541A /* PostHogObjCExample */, 3AC745B6296D6FE60025C109 /* Products */, 69261D152AD92D6C00232EC7 /* Frameworks */, ); @@ -251,6 +299,7 @@ 3AC745B5296D6FE60025C109 /* PostHog.framework */, 3AC745BF296D6FE60025C109 /* PostHogTests.xctest */, 3AA34CF7296D951A003398F4 /* PostHogExample.app */, + 69278D322AE6BC7100BB541A /* PostHogObjCExample.app */, ); name = Products; sourceTree = ""; @@ -300,6 +349,24 @@ name = Frameworks; sourceTree = ""; }; + 69278D332AE6BC7100BB541A /* PostHogObjCExample */ = { + isa = PBXGroup; + children = ( + 69278D342AE6BC7100BB541A /* AppDelegate.h */, + 69278D352AE6BC7100BB541A /* AppDelegate.m */, + 69278D372AE6BC7100BB541A /* SceneDelegate.h */, + 69278D382AE6BC7100BB541A /* SceneDelegate.m */, + 69278D3A2AE6BC7100BB541A /* ViewController.h */, + 69278D3B2AE6BC7100BB541A /* ViewController.m */, + 69278D3D2AE6BC7100BB541A /* Main.storyboard */, + 69278D402AE6BC7200BB541A /* Assets.xcassets */, + 69278D422AE6BC7200BB541A /* LaunchScreen.storyboard */, + 69278D452AE6BC7200BB541A /* Info.plist */, + 69278D462AE6BC7200BB541A /* main.m */, + ); + path = PostHogObjCExample; + sourceTree = ""; + }; 69779BED2AE6B29E00D7A48E /* Models */ = { isa = PBXGroup; children = ( @@ -388,6 +455,25 @@ productReference = 3AC745BF296D6FE60025C109 /* PostHogTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; + 69278D312AE6BC7100BB541A /* PostHogObjCExample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 69278D482AE6BC7200BB541A /* Build configuration list for PBXNativeTarget "PostHogObjCExample" */; + buildPhases = ( + 69278D2E2AE6BC7100BB541A /* Sources */, + 69278D2F2AE6BC7100BB541A /* Frameworks */, + 69278D302AE6BC7100BB541A /* Resources */, + 69278D4F2AE6BC9000BB541A /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + 69278D4E2AE6BC9000BB541A /* PBXTargetDependency */, + ); + name = PostHogObjCExample; + productName = PostHogObjCExample; + productReference = 69278D322AE6BC7100BB541A /* PostHogObjCExample.app */; + productType = "com.apple.product-type.application"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -409,6 +495,9 @@ CreatedOnToolsVersion = 14.2; LastSwiftMigration = 1420; }; + 69278D312AE6BC7100BB541A = { + CreatedOnToolsVersion = 15.0.1; + }; }; }; buildConfigurationList = 3AC745AF296D6FE60025C109 /* Build configuration list for PBXProject "PostHog" */; @@ -433,6 +522,7 @@ 3AC745B4296D6FE60025C109 /* PostHog */, 3AC745BE296D6FE60025C109 /* PostHogTests */, 3AA34CF6296D951A003398F4 /* PostHogExample */, + 69278D312AE6BC7100BB541A /* PostHogObjCExample */, ); }; /* End PBXProject section */ @@ -461,6 +551,16 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 69278D302AE6BC7100BB541A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 69278D442AE6BC7200BB541A /* LaunchScreen.storyboard in Resources */, + 69278D412AE6BC7200BB541A /* Assets.xcassets in Resources */, + 69278D3F2AE6BC7100BB541A /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -521,6 +621,17 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 69278D2E2AE6BC7100BB541A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 69278D3C2AE6BC7100BB541A /* ViewController.m in Sources */, + 69278D362AE6BC7100BB541A /* AppDelegate.m in Sources */, + 69278D472AE6BC7200BB541A /* main.m in Sources */, + 69278D392AE6BC7100BB541A /* SceneDelegate.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -539,8 +650,32 @@ target = 3AC745B4296D6FE60025C109 /* PostHog */; targetProxy = 3AC745C1296D6FE60025C109 /* PBXContainerItemProxy */; }; + 69278D4E2AE6BC9000BB541A /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 3AC745B4296D6FE60025C109 /* PostHog */; + targetProxy = 69278D4D2AE6BC9000BB541A /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ +/* Begin PBXVariantGroup section */ + 69278D3D2AE6BC7100BB541A /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 69278D3E2AE6BC7100BB541A /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 69278D422AE6BC7200BB541A /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 69278D432AE6BC7200BB541A /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ 3AA34D03296D951B003398F4 /* Debug */ = { isa = XCBuildConfiguration; @@ -861,6 +996,68 @@ }; name = Release; }; + 69278D492AE6BC7200BB541A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = PNC2XCH2XP; + GCC_C_LANGUAGE_STANDARD = gnu17; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = PostHogObjCExample/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; + INFOPLIST_KEY_UIMainStoryboardFile = Main; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.posthog.PostHogObjCExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 69278D4A2AE6BC7200BB541A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = PNC2XCH2XP; + GCC_C_LANGUAGE_STANDARD = gnu17; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = PostHogObjCExample/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; + INFOPLIST_KEY_UIMainStoryboardFile = Main; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.posthog.PostHogObjCExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -900,6 +1097,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 69278D482AE6BC7200BB541A /* Build configuration list for PBXNativeTarget "PostHogObjCExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 69278D492AE6BC7200BB541A /* Debug */, + 69278D4A2AE6BC7200BB541A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ diff --git a/PostHog.xcodeproj/xcshareddata/xcschemes/PostHogObjCExample.xcscheme b/PostHog.xcodeproj/xcshareddata/xcschemes/PostHogObjCExample.xcscheme new file mode 100644 index 000000000..73e49b772 --- /dev/null +++ b/PostHog.xcodeproj/xcshareddata/xcschemes/PostHogObjCExample.xcscheme @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PostHog/PostHogConfig.swift b/PostHog/PostHogConfig.swift index 40da7f1ff..bcb2cc0a1 100644 --- a/PostHog/PostHogConfig.swift +++ b/PostHog/PostHogConfig.swift @@ -28,6 +28,15 @@ import Foundation @objc public var optOut: Bool = false public static let defaultHost: String = "https://app.posthog.com" + @objc(apiKey:) + public init( + apiKey: String + ) { + self.apiKey = apiKey + host = URL(string: PostHogConfig.defaultHost)! + } + + @objc(apiKey:host:) public init( apiKey: String, host: String = defaultHost diff --git a/PostHog/PostHogExtensions.swift b/PostHog/PostHogExtensions.swift index ef34deeee..4f701e69b 100644 --- a/PostHog/PostHogExtensions.swift +++ b/PostHog/PostHogExtensions.swift @@ -15,6 +15,6 @@ import Foundation */ public extension PostHogSDK { - static let didStartNotification = Notification.Name("PostHogDidStart") // object: nil - static let didReceiveFeatureFlags = Notification.Name("PostHogDidReceiveFeatureFlags") // object: nil + @objc static let didStartNotification = Notification.Name("PostHogDidStart") // object: nil + @objc static let didReceiveFeatureFlags = Notification.Name("PostHogDidReceiveFeatureFlags") // object: nil } diff --git a/PostHog/PostHogFeatureFlags.swift b/PostHog/PostHogFeatureFlags.swift index 6eec7629b..303b4a785 100644 --- a/PostHog/PostHogFeatureFlags.swift +++ b/PostHog/PostHogFeatureFlags.swift @@ -34,7 +34,7 @@ class PostHogFeatureFlags { distinctId: String, anonymousId: String, groups: [String: String], - completion: @escaping ([String: Any]?, [String: Any]?) -> Void + callback: @escaping () -> Void ) { isLoadingLock.withLock { if self.isLoadingFeatureFlags { @@ -53,7 +53,7 @@ class PostHogFeatureFlags { else { hedgeLog("Error: Decide response missing correct featureFlags format") self.setLoading(false) - return completion(nil, nil) + return callback() } let errorsWhileComputingFlags = data?["errorsWhileComputingFlags"] as? Bool ?? false @@ -80,7 +80,7 @@ class PostHogFeatureFlags { self.setLoading(false) - return completion(featureFlags, featureFlagPayloads) + return callback() } } } @@ -94,13 +94,13 @@ class PostHogFeatureFlags { return flags } - func isFeatureEnabled(_ flagKey: String) -> Bool { + func isFeatureEnabled(_ key: String) -> Bool { var flags: [String: Any]? featureFlagsLock.withLock { flags = self.storage.getDictionary(forKey: .enabledFeatureFlags) as? [String: Any] } - let value = flags?[flagKey] + let value = flags?[key] if value != nil { let boolValue = value as? Bool ?? false @@ -114,22 +114,22 @@ class PostHogFeatureFlags { } } - func getFeatureFlag(_ flagKey: String) -> Any? { + func getFeatureFlag(_ key: String) -> Any? { var flags: [String: Any]? featureFlagsLock.withLock { flags = self.storage.getDictionary(forKey: .enabledFeatureFlags) as? [String: Any] } - return flags?[flagKey] + return flags?[key] } - func getFeatureFlagPayload(_ flagKey: String) -> Any? { + func getFeatureFlagPayload(_ key: String) -> Any? { var flags: [String: Any]? featureFlagsLock.withLock { flags = self.storage.getDictionary(forKey: .enabledFeatureFlagPayloads) as? [String: Any] } - let value = flags?[flagKey] + let value = flags?[key] guard let stringValue = value as? String else { return value diff --git a/PostHog/PostHogSDK.swift b/PostHog/PostHogSDK.swift index 47046d92b..fbd0217d8 100644 --- a/PostHog/PostHogSDK.swift +++ b/PostHog/PostHogSDK.swift @@ -49,7 +49,7 @@ let maxRetryDelay = 30.0 self.reachability?.stopNotifier() } - @objc public func debug(enabled: Bool = true) { + @objc public func debug(_ enabled: Bool = true) { if !isEnabled() { return } @@ -219,7 +219,9 @@ let maxRetryDelay = 30.0 return props } - @objc public func register(_ properties: [String: Any]) { + // register is a reserved word in ObjC + @objc(registerProperties:) + public func register(_ properties: [String: Any]) { if !isEnabled() { return } @@ -232,7 +234,8 @@ let maxRetryDelay = 30.0 } } - @objc public func unregister(_ key: String) { + @objc(unregisterProperties:) + public func unregister(_ key: String) { personPropsLock.withLock { var props = getRegisteredProperties() props.removeValue(forKey: key) @@ -240,10 +243,21 @@ let maxRetryDelay = 30.0 } } - @objc public func identify(_ distinctId: String, - properties _: [String: Any]? = nil, - userProperties: [String: Any]? = nil, - userPropertiesSetOnce: [String: Any]? = nil) + @objc public func identify(_ distinctId: String) { + identify(distinctId, userProperties: nil, userPropertiesSetOnce: nil) + } + + @objc(identifyWithDistinctId:userProperties:) + public func identify(_ distinctId: String, + userProperties: [String: Any]? = nil) + { + identify(distinctId, userProperties: userProperties, userPropertiesSetOnce: nil) + } + + @objc(identifyWithDistinctId:userProperties:userPropertiesSetOnce:) + public func identify(_ distinctId: String, + userProperties: [String: Any]? = nil, + userPropertiesSetOnce: [String: Any]? = nil) { if !isEnabled() { return @@ -272,11 +286,40 @@ let maxRetryDelay = 30.0 } } - @objc public func capture(_ event: String, - properties: [String: Any]? = nil, - userProperties: [String: Any]? = nil, - userPropertiesSetOnce: [String: Any]? = nil, - groupProperties: [String: Any]? = nil) + @objc public func capture(_ event: String) { + capture(event, properties: nil, userProperties: nil, userPropertiesSetOnce: nil, groupProperties: nil) + } + + @objc(captureWithEvent:properties:) + public func capture(_ event: String, + properties: [String: Any]? = nil) + { + capture(event, properties: properties, userProperties: nil, userPropertiesSetOnce: nil, groupProperties: nil) + } + + @objc(captureWithEvent:properties:userProperties:) + public func capture(_ event: String, + properties: [String: Any]? = nil, + userProperties: [String: Any]? = nil) + { + capture(event, properties: properties, userProperties: userProperties, userPropertiesSetOnce: nil, groupProperties: nil) + } + + @objc(captureWithEvent:properties:userProperties:userPropertiesSetOnce:) + public func capture(_ event: String, + properties: [String: Any]? = nil, + userProperties: [String: Any]? = nil, + userPropertiesSetOnce: [String: Any]? = nil) + { + capture(event, properties: properties, userProperties: userProperties, userPropertiesSetOnce: userPropertiesSetOnce, groupProperties: nil) + } + + @objc(captureWithEvent:properties:userProperties:userPropertiesSetOnce:groupProperties:) + public func capture(_ event: String, + properties: [String: Any]? = nil, + userProperties: [String: Any]? = nil, + userPropertiesSetOnce: [String: Any]? = nil, + groupProperties: [String: Any]? = nil) { if !isEnabled() { return @@ -295,7 +338,12 @@ let maxRetryDelay = 30.0 )) } - @objc public func screen(_ screenTitle: String, properties: [String: Any]? = nil) { + @objc public func screen(_ screenTitle: String) { + screen(screenTitle, properties: nil) + } + + @objc(screenWithTitle:properties:) + public func screen(_ screenTitle: String, properties: [String: Any]? = nil) { if !isEnabled() { return } @@ -315,7 +363,7 @@ let maxRetryDelay = 30.0 )) } - @objc public func alias(_ alias: String, properties: [String: Any]? = nil) { + @objc public func alias(_ alias: String) { if !isEnabled() { return } @@ -324,9 +372,7 @@ let maxRetryDelay = 30.0 return } - let props = [ - "alias": alias, - ].merging(properties ?? [:]) { prop, _ in prop } + let props = ["alias": alias] queue.add(PostHogEvent( event: "$create_alias", @@ -363,7 +409,7 @@ let maxRetryDelay = 30.0 return mergedGroups ?? [:] } - @objc public func groupIdentify(type: String, key: String, groupProperties: [String: Any]? = nil) { + private func groupIdentify(type: String, key: String, groupProperties: [String: Any]? = nil) { if !isEnabled() { return } @@ -383,7 +429,13 @@ let maxRetryDelay = 30.0 )) } - @objc public func group(type: String, key: String, groupProperties: [String: Any]? = nil) { + @objc(groupWithType:key:) + public func group(type: String, key: String) { + group(type: type, key: key, groupProperties: nil) + } + + @objc(groupWithType:key:groupProperties:) + public func group(type: String, key: String, groupProperties: [String: Any]? = nil) { if !isEnabled() { return } @@ -397,12 +449,13 @@ let maxRetryDelay = 30.0 // FEATURE FLAGS @objc public func reloadFeatureFlags() { - reloadFeatureFlags { _, _ in + reloadFeatureFlags { // No use case } } - @objc public func reloadFeatureFlags(_ completion: @escaping ([String: Any]?, [String: Any]?) -> Void) { + @objc(reloadFeatureFlagsWithCallback:) + public func reloadFeatureFlags(_ callback: @escaping () -> Void) { if !isEnabled() { return } @@ -419,11 +472,11 @@ let maxRetryDelay = 30.0 distinctId: sessionManager.getDistinctId(), anonymousId: sessionManager.getAnonymousId(), groups: groups ?? [:], - completion: completion + callback: callback ) } - @objc public func getFeatureFlag(_ flagKey: String) -> Any? { + @objc public func getFeatureFlag(_ key: String) -> Any? { if !isEnabled() { return nil } @@ -432,16 +485,16 @@ let maxRetryDelay = 30.0 return nil } - let value = featureFlags.getFeatureFlag(flagKey) + let value = featureFlags.getFeatureFlag(key) if config.sendFeatureFlagEvent { - reportFeatureFlagCalled(flagKey: flagKey, flagValue: value) + reportFeatureFlagCalled(flagKey: key, flagValue: value) } return value } - @objc public func isFeatureEnabled(_ flagKey: String) -> Bool { + @objc public func isFeatureEnabled(_ key: String) -> Bool { if !isEnabled() { return false } @@ -450,10 +503,10 @@ let maxRetryDelay = 30.0 return false } - return featureFlags.isFeatureEnabled(flagKey) + return featureFlags.isFeatureEnabled(key) } - @objc public func getFeatureFlagPayload(_ flagKey: String) -> Any? { + @objc public func getFeatureFlagPayload(_ key: String) -> Any? { if !isEnabled() { return nil } @@ -462,7 +515,7 @@ let maxRetryDelay = 30.0 return nil } - return featureFlags.getFeatureFlagPayload(flagKey) + return featureFlags.getFeatureFlagPayload(key) } private func reportFeatureFlagCalled(flagKey: String, flagValue: Any?) { diff --git a/PostHogExample/AppDelegate.swift b/PostHogExample/AppDelegate.swift index 94cea027b..b7031621b 100644 --- a/PostHogExample/AppDelegate.swift +++ b/PostHogExample/AppDelegate.swift @@ -28,19 +28,19 @@ class AppDelegate: NSObject, UIApplicationDelegate { // "iteration": iteration // ]) // } - + let defaultCenter = NotificationCenter.default #if os(iOS) || os(tvOS) defaultCenter.addObserver(self, - selector: #selector(self.receiveFeatureFlags), + selector: #selector(receiveFeatureFlags), name: PostHogSDK.didReceiveFeatureFlags, object: nil) #endif return true } - + @objc func receiveFeatureFlags() { print("receiveFeatureFlags") } diff --git a/PostHogExample/ContentView.swift b/PostHogExample/ContentView.swift index 0f5cb8fed..d2e258465 100644 --- a/PostHogExample/ContentView.swift +++ b/PostHogExample/ContentView.swift @@ -55,7 +55,7 @@ class FeatureFlagsModel: ObservableObject { func reload() { isReloading = true - PostHogSDK.shared.reloadFeatureFlags { _, _ in + PostHogSDK.shared.reloadFeatureFlags { self.isReloading = false } } diff --git a/PostHogObjCExample/AppDelegate.h b/PostHogObjCExample/AppDelegate.h new file mode 100644 index 000000000..addf60dec --- /dev/null +++ b/PostHogObjCExample/AppDelegate.h @@ -0,0 +1,14 @@ +// +// AppDelegate.h +// PostHogObjCExample +// +// Created by Manoel Aranda Neto on 23.10.23. +// + +#import + +@interface AppDelegate : UIResponder + + +@end + diff --git a/PostHogObjCExample/AppDelegate.m b/PostHogObjCExample/AppDelegate.m new file mode 100644 index 000000000..6e5a343c5 --- /dev/null +++ b/PostHogObjCExample/AppDelegate.m @@ -0,0 +1,114 @@ +// +// AppDelegate.m +// PostHogObjCExample +// +// Created by Manoel Aranda Neto on 23.10.23. +// + +#import "AppDelegate.h" +#import + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (void)receiveTestNotification { + NSLog(@"received"); +} + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(receiveTestNotification) + name:PostHogSDK.didStartNotification + object:nil]; + + PostHogConfig *config = [[PostHogConfig alloc] apiKey:@"_6SG-F7I1vCuZ-HdJL3VZQqjBlaSb1_20hDPwqMNnGI"]; + config.preloadFeatureFlags = NO; + [[PostHogSDK shared] debug:YES]; + [[PostHogSDK shared] setup:config]; + NSLog(@"getDistinctId: %@", [[PostHogSDK shared] getDistinctId]); + NSLog(@"getAnonymousId: %@", [[PostHogSDK shared] getAnonymousId]); + + NSMutableDictionary *props = [NSMutableDictionary dictionary]; + props[@"state"] = @"running"; + + NSMutableDictionary *userProps = [NSMutableDictionary dictionary]; + userProps[@"userAge"] = @50; + + NSMutableDictionary *userPropsOnce = [NSMutableDictionary dictionary]; + userPropsOnce[@"userAlive"] = @YES; + + NSMutableDictionary *groupProps = [NSMutableDictionary dictionary]; + groupProps[@"groupName"] = @"theGroup"; + + NSMutableDictionary *registerProps = [NSMutableDictionary dictionary]; + props[@"loggedIn"] = @YES; + [[PostHogSDK shared] registerProperties:registerProps]; + [[PostHogSDK shared] unregisterProperties:@"test2"]; + + [[PostHogSDK shared] identify:@"my_new_id"]; + [[PostHogSDK shared] identifyWithDistinctId:@"my_new_id" userProperties:userProps]; + [[PostHogSDK shared] identifyWithDistinctId:@"my_new_id" userProperties:userProps userPropertiesSetOnce:userPropsOnce]; + + + [[PostHogSDK shared] optIn]; + [[PostHogSDK shared] optOut]; + NSLog(@"isOptOut: %d", [[PostHogSDK shared] isOptOut]); + NSLog(@"isFeatureEnabled: %d", [[PostHogSDK shared] isFeatureEnabled:@"myFlag"]); + NSLog(@"getFeatureFlag: %@", [[PostHogSDK shared] getFeatureFlag:@"myFlag"]); + NSLog(@"getFeatureFlagPayload: %@", [[PostHogSDK shared] getFeatureFlagPayload:@"myFlag"]); + + [[PostHogSDK shared] reloadFeatureFlags]; + [[PostHogSDK shared] reloadFeatureFlagsWithCallback:^(){ + NSLog(@"called"); + }]; + + [[PostHogSDK shared] capture:@"theEvent"]; + [[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props]; + [[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props userProperties:userProps]; + [[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props userProperties:userProps userPropertiesSetOnce:userPropsOnce]; + [[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props userProperties:userProps userPropertiesSetOnce:userPropsOnce groupProperties:groupProps]; + + [[PostHogSDK shared] groupWithType:@"theType" key:@"theKey"]; + [[PostHogSDK shared] groupWithType:@"theType" key:@"theKey" groupProperties:groupProps]; + + [[PostHogSDK shared] alias:@"theAlias"]; + + [[PostHogSDK shared] screen:@"theScreen"]; + [[PostHogSDK shared] screenWithTitle:@"theScreen" properties:props]; + + [[PostHogSDK shared] flush]; + [[PostHogSDK shared] reset]; + [[PostHogSDK shared] close]; + + PostHogSDK *postHog = [PostHogSDK with:config]; + + [postHog capture:@"theCapture"]; + + return YES; +} + + +#pragma mark - UISceneSession lifecycle + + +- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; +} + + +- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. +} + + +@end diff --git a/PostHogObjCExample/Assets.xcassets/AccentColor.colorset/Contents.json b/PostHogObjCExample/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 000000000..eb8789700 --- /dev/null +++ b/PostHogObjCExample/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PostHogObjCExample/Assets.xcassets/AppIcon.appiconset/Contents.json b/PostHogObjCExample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..13613e3ee --- /dev/null +++ b/PostHogObjCExample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,13 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PostHogObjCExample/Assets.xcassets/Contents.json b/PostHogObjCExample/Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/PostHogObjCExample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PostHogObjCExample/Base.lproj/LaunchScreen.storyboard b/PostHogObjCExample/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 000000000..865e9329f --- /dev/null +++ b/PostHogObjCExample/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PostHogObjCExample/Base.lproj/Main.storyboard b/PostHogObjCExample/Base.lproj/Main.storyboard new file mode 100644 index 000000000..808a21ce7 --- /dev/null +++ b/PostHogObjCExample/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PostHogObjCExample/Info.plist b/PostHogObjCExample/Info.plist new file mode 100644 index 000000000..81ed29b76 --- /dev/null +++ b/PostHogObjCExample/Info.plist @@ -0,0 +1,25 @@ + + + + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + SceneDelegate + UISceneStoryboardFile + Main + + + + + + diff --git a/PostHogObjCExample/SceneDelegate.h b/PostHogObjCExample/SceneDelegate.h new file mode 100644 index 000000000..2da18f216 --- /dev/null +++ b/PostHogObjCExample/SceneDelegate.h @@ -0,0 +1,15 @@ +// +// SceneDelegate.h +// PostHogObjCExample +// +// Created by Manoel Aranda Neto on 23.10.23. +// + +#import + +@interface SceneDelegate : UIResponder + +@property (strong, nonatomic) UIWindow * window; + +@end + diff --git a/PostHogObjCExample/SceneDelegate.m b/PostHogObjCExample/SceneDelegate.m new file mode 100644 index 000000000..8564c7dca --- /dev/null +++ b/PostHogObjCExample/SceneDelegate.m @@ -0,0 +1,57 @@ +// +// SceneDelegate.m +// PostHogObjCExample +// +// Created by Manoel Aranda Neto on 23.10.23. +// + +#import "SceneDelegate.h" + +@interface SceneDelegate () + +@end + +@implementation SceneDelegate + + +- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). +} + + +- (void)sceneDidDisconnect:(UIScene *)scene { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). +} + + +- (void)sceneDidBecomeActive:(UIScene *)scene { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. +} + + +- (void)sceneWillResignActive:(UIScene *)scene { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). +} + + +- (void)sceneWillEnterForeground:(UIScene *)scene { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. +} + + +- (void)sceneDidEnterBackground:(UIScene *)scene { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. +} + + +@end diff --git a/PostHogObjCExample/ViewController.h b/PostHogObjCExample/ViewController.h new file mode 100644 index 000000000..0d5f9ffc3 --- /dev/null +++ b/PostHogObjCExample/ViewController.h @@ -0,0 +1,14 @@ +// +// ViewController.h +// PostHogObjCExample +// +// Created by Manoel Aranda Neto on 23.10.23. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/PostHogObjCExample/ViewController.m b/PostHogObjCExample/ViewController.m new file mode 100644 index 000000000..2bdefee37 --- /dev/null +++ b/PostHogObjCExample/ViewController.m @@ -0,0 +1,22 @@ +// +// ViewController.m +// PostHogObjCExample +// +// Created by Manoel Aranda Neto on 23.10.23. +// + +#import "ViewController.h" + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. +} + + +@end diff --git a/PostHogObjCExample/main.m b/PostHogObjCExample/main.m new file mode 100644 index 000000000..0db7ddacb --- /dev/null +++ b/PostHogObjCExample/main.m @@ -0,0 +1,18 @@ +// +// main.m +// PostHogObjCExample +// +// Created by Manoel Aranda Neto on 23.10.23. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + NSString * appDelegateClassName; + @autoreleasepool { + // Setup code that might create autoreleased objects goes here. + appDelegateClassName = NSStringFromClass([AppDelegate class]); + } + return UIApplicationMain(argc, argv, nil, appDelegateClassName); +}