From e52ab5e785a7f77d1d6f16c0986795ceb1d4305a Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Mon, 23 Oct 2023 18:12:16 +0200 Subject: [PATCH] Add ObjC example and add method annotations --- PostHog.xcodeproj/project.pbxproj | 206 ++++++++++++++++++ .../xcschemes/PostHogObjCExample.xcscheme | 77 +++++++ PostHog/PostHogConfig.swift | 9 + PostHog/PostHogSDK.swift | 83 ++++++- PostHogExample/AppDelegate.swift | 6 +- PostHogObjCExample/AppDelegate.h | 14 ++ PostHogObjCExample/AppDelegate.m | 61 ++++++ .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 13 ++ .../Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 25 +++ PostHogObjCExample/Base.lproj/Main.storyboard | 24 ++ PostHogObjCExample/Info.plist | 25 +++ PostHogObjCExample/SceneDelegate.h | 15 ++ PostHogObjCExample/SceneDelegate.m | 57 +++++ PostHogObjCExample/ViewController.h | 14 ++ PostHogObjCExample/ViewController.m | 22 ++ PostHogObjCExample/main.m | 18 ++ 18 files changed, 671 insertions(+), 15 deletions(-) create mode 100644 PostHog.xcodeproj/xcshareddata/xcschemes/PostHogObjCExample.xcscheme create mode 100644 PostHogObjCExample/AppDelegate.h create mode 100644 PostHogObjCExample/AppDelegate.m create mode 100644 PostHogObjCExample/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 PostHogObjCExample/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 PostHogObjCExample/Assets.xcassets/Contents.json create mode 100644 PostHogObjCExample/Base.lproj/LaunchScreen.storyboard create mode 100644 PostHogObjCExample/Base.lproj/Main.storyboard create mode 100644 PostHogObjCExample/Info.plist create mode 100644 PostHogObjCExample/SceneDelegate.h create mode 100644 PostHogObjCExample/SceneDelegate.m create mode 100644 PostHogObjCExample/ViewController.h create mode 100644 PostHogObjCExample/ViewController.m create mode 100644 PostHogObjCExample/main.m 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/PostHogSDK.swift b/PostHog/PostHogSDK.swift index 47046d92b..bb96c3988 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 } @@ -240,10 +240,30 @@ 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, properties: nil, userProperties: nil, userPropertiesSetOnce: nil) + } + + @objc(distinctId:properties:) + public func identify(_ distinctId: String, + properties: [String: Any]? = nil) + { + identify(distinctId, properties: properties, userProperties: nil, userPropertiesSetOnce: nil) + } + + @objc(distinctId:properties:userProperties:) + public func identify(_ distinctId: String, + properties: [String: Any]? = nil, + userProperties: [String: Any]? = nil) + { + identify(distinctId, properties: properties, userProperties: userProperties, userPropertiesSetOnce: nil) + } + + @objc(distinctId:properties:userProperties:userPropertiesSetOnce:) + public func identify(_ distinctId: String, + properties _: [String: Any]? = nil, + userProperties: [String: Any]? = nil, + userPropertiesSetOnce: [String: Any]? = nil) { if !isEnabled() { return @@ -272,11 +292,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(event:properties:) + public func capture(_ event: String, + properties: [String: Any]? = nil) + { + capture(event, properties: properties, userProperties: nil, userPropertiesSetOnce: nil, groupProperties: nil) + } + + @objc(event: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(event: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(event: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 @@ -294,8 +343,13 @@ let maxRetryDelay = 30.0 groupProperties: groupProperties) )) } + + @objc public func screen(_ screenTitle: String) { + screen(screenTitle, properties: nil) + } - @objc public func screen(_ screenTitle: String, properties: [String: Any]? = nil) { + @objc(screenTitle:properties:) + public func screen(_ screenTitle: String, properties: [String: Any]? = nil) { if !isEnabled() { return } @@ -314,8 +368,13 @@ let maxRetryDelay = 30.0 properties: buildProperties(properties: props) )) } + + @objc public func alias(_ alias: String) { + self.alias(alias, properties: nil) + } - @objc public func alias(_ alias: String, properties: [String: Any]? = nil) { + @objc(alias:properties:) + public func alias(_ alias: String, properties: [String: Any]? = nil) { if !isEnabled() { return } 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/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..90f3a6873 --- /dev/null +++ b/PostHogObjCExample/AppDelegate.m @@ -0,0 +1,61 @@ +// +// AppDelegate.m +// PostHogObjCExample +// +// Created by Manoel Aranda Neto on 23.10.23. +// + +#import "AppDelegate.h" +#import + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + + 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[@"test"] = @"testValue"; + props[@"test2"] = @"testValue2"; + [[PostHogSDK shared] register:props]; + [[PostHogSDK shared] unregister:@"test2"]; + [[PostHogSDK shared] identify:@"my_new_id"]; + [[PostHogSDK shared] flush]; + [[PostHogSDK shared] reset]; + + +// [[PostHogSDK shared] close]; + + 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); +}