diff --git a/.swiftlint.yml b/.swiftlint.yml index 2bb918609..fc619f0f6 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,12 +1,10 @@ excluded: # case-sensitive paths to ignore during linting. Takes precedence over `included` - PostHogExample + - PostHogExampleWithSPM - PostHogTests - - PostHog/Recording - - PostHog/Utils/MethodSwizzler.swift - PostHog/Utils/ReadWriteLock.swift - PostHog/Utils/Reachability.swift - - PostHog/Utils/NSData+PHGGZIP.h - - PostHog/Utils/NSData+PHGGZIP.m + - PostHog/Utils/Data+Gzip.swift - .build - Pods diff --git a/PostHog.xcodeproj/project.pbxproj b/PostHog.xcodeproj/project.pbxproj index 9b896f59a..c23618bc2 100644 --- a/PostHog.xcodeproj/project.pbxproj +++ b/PostHog.xcodeproj/project.pbxproj @@ -12,14 +12,12 @@ 3A0F108929C9BD76002C0084 /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A0F108829C9BD76002C0084 /* Errors.swift */; }; 3A2BCF4C299E4E35008BB5F3 /* QueueTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A2BCF4B299E4E35008BB5F3 /* QueueTest.swift */; }; 3A2BCF52299F7724008BB5F3 /* CodableUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A2BCF51299F7724008BB5F3 /* CodableUtils.swift */; }; - 3A4F510D299A78E100B68D5E /* NSData+PHGGZIP.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AE3FB3829924CE100AFFC18 /* NSData+PHGGZIP.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3A580B3F29E481F200C5C6F3 /* OHHTTPStubs in Frameworks */ = {isa = PBXBuildFile; productRef = 3A580B3E29E481F200C5C6F3 /* OHHTTPStubs */; }; 3A580B4129E481F200C5C6F3 /* OHHTTPStubsSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 3A580B4029E481F200C5C6F3 /* OHHTTPStubsSwift */; }; 3A580B4329E489D000C5C6F3 /* URLSession+body.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A580B4229E489D000C5C6F3 /* URLSession+body.swift */; }; 3A62646429C9E0E7007E8C07 /* PostHogTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A62646329C9E0E7007E8C07 /* PostHogTest.swift */; }; 3A62646729C9E36B007E8C07 /* Shock in Frameworks */ = {isa = PBXBuildFile; productRef = 3A62646629C9E36B007E8C07 /* Shock */; }; 3A62646A29C9E385007E8C07 /* MockPostHogServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A62646929C9E385007E8C07 /* MockPostHogServer.swift */; }; - 3A62646F29C9ECDA007E8C07 /* NSData+PHGGUNZIPP.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A62646E29C9ECDA007E8C07 /* NSData+PHGGUNZIPP.m */; }; 3A62647129CAF67B007E8C07 /* SessionManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A62647029CAF67B007E8C07 /* SessionManagerTest.swift */; }; 3A62647329CB0043007E8C07 /* CaptureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A62647229CB0043007E8C07 /* CaptureTests.swift */; }; 3A62647529CB0168007E8C07 /* TestPostHog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A62647429CB0168007E8C07 /* TestPostHog.swift */; }; @@ -38,7 +36,6 @@ 3AE3FB2C2991320300AFFC18 /* Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB2B2991320300AFFC18 /* Api.swift */; }; 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 /* 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 */; }; @@ -46,6 +43,7 @@ 3AE3FB49299391DF00AFFC18 /* PostHogStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB48299391DF00AFFC18 /* PostHogStorage.swift */; }; 3AE3FB4B2993A68500AFFC18 /* StorageTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB4A2993A68500AFFC18 /* StorageTest.swift */; }; 3AE3FB4E2993D1D600AFFC18 /* PostHogSessionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3FB4D2993D1D600AFFC18 /* PostHogSessionManager.swift */; }; + 690FF05F2AE7E2D400A0B06B /* Data+Gzip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 690FF05E2AE7E2D400A0B06B /* Data+Gzip.swift */; }; 69261D132AD5685B00232EC7 /* PostHogFeatureFlags.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69261D122AD5685B00232EC7 /* PostHogFeatureFlags.swift */; }; 69261D192AD9673500232EC7 /* PostHogBatchUploadInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69261D182AD9673500232EC7 /* PostHogBatchUploadInfo.swift */; }; 69261D1B2AD9678C00232EC7 /* PostHogEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69261D1A2AD9678C00232EC7 /* PostHogEvent.swift */; }; @@ -95,6 +93,13 @@ remoteGlobalIDString = 690FF01E2AE7C5B900A0B06B; remoteInfo = PostHogExampleWithPods; }; + 690FF0572AE7DB3700A0B06B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 690FF0532AE7DB3700A0B06B /* PostHogExampleWithSPM.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 690FF0422AE7DB3600A0B06B; + remoteInfo = PostHogExampleWithSPM; + }; 69278D4D2AE6BC9000BB541A /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 3AC745AC296D6FE60025C109 /* Project object */; @@ -138,9 +143,6 @@ 3A580B4229E489D000C5C6F3 /* URLSession+body.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URLSession+body.swift"; sourceTree = ""; }; 3A62646329C9E0E7007E8C07 /* PostHogTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogTest.swift; sourceTree = ""; }; 3A62646929C9E385007E8C07 /* MockPostHogServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockPostHogServer.swift; sourceTree = ""; }; - 3A62646C29C9ECD9007E8C07 /* PostHogTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PostHogTests-Bridging-Header.h"; sourceTree = ""; }; - 3A62646D29C9ECDA007E8C07 /* NSData+PHGGUNZIPP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+PHGGUNZIPP.h"; sourceTree = ""; }; - 3A62646E29C9ECDA007E8C07 /* NSData+PHGGUNZIPP.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+PHGGUNZIPP.m"; sourceTree = ""; }; 3A62647029CAF67B007E8C07 /* SessionManagerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionManagerTest.swift; sourceTree = ""; }; 3A62647229CB0043007E8C07 /* CaptureTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureTests.swift; sourceTree = ""; }; 3A62647429CB0168007E8C07 /* TestPostHog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestPostHog.swift; sourceTree = ""; }; @@ -158,8 +160,6 @@ 3AE3FB2B2991320300AFFC18 /* Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Api.swift; sourceTree = ""; }; 3AE3FB322991388500AFFC18 /* PostHogQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogQueue.swift; sourceTree = ""; }; 3AE3FB36299162EA00AFFC18 /* PostHogApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogApi.swift; sourceTree = ""; }; - 3AE3FB3829924CE100AFFC18 /* NSData+PHGGZIP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+PHGGZIP.h"; sourceTree = ""; }; - 3AE3FB3929924CE100AFFC18 /* NSData+PHGGZIP.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+PHGGZIP.m"; sourceTree = ""; }; 3AE3FB3C29924E8200AFFC18 /* PostHogSDK.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogSDK.swift; sourceTree = ""; }; 3AE3FB3E29924F4F00AFFC18 /* PostHogConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogConfig.swift; sourceTree = ""; }; 3AE3FB422992985A00AFFC18 /* Reachability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = ""; }; @@ -168,6 +168,8 @@ 3AE3FB4A2993A68500AFFC18 /* StorageTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageTest.swift; sourceTree = ""; }; 3AE3FB4D2993D1D600AFFC18 /* PostHogSessionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogSessionManager.swift; sourceTree = ""; }; 690FF02F2AE7C5BA00A0B06B /* PostHogExampleWithPods.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = PostHogExampleWithPods.xcodeproj; path = PostHogExampleWithPods/PostHogExampleWithPods.xcodeproj; sourceTree = ""; }; + 690FF0532AE7DB3700A0B06B /* PostHogExampleWithSPM.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = PostHogExampleWithSPM.xcodeproj; path = PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj; sourceTree = ""; }; + 690FF05E2AE7E2D400A0B06B /* Data+Gzip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Gzip.swift"; sourceTree = ""; }; 69261D122AD5685B00232EC7 /* PostHogFeatureFlags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogFeatureFlags.swift; sourceTree = ""; }; 69261D182AD9673500232EC7 /* PostHogBatchUploadInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogBatchUploadInfo.swift; sourceTree = ""; }; 69261D1A2AD9678C00232EC7 /* PostHogEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogEvent.swift; sourceTree = ""; }; @@ -242,11 +244,8 @@ 3A62646829C9E37A007E8C07 /* TestUtils */ = { isa = PBXGroup; children = ( - 3A62646D29C9ECDA007E8C07 /* NSData+PHGGUNZIPP.h */, - 3A62646E29C9ECDA007E8C07 /* NSData+PHGGUNZIPP.m */, 3A62646929C9E385007E8C07 /* MockPostHogServer.swift */, 3A62647429CB0168007E8C07 /* TestPostHog.swift */, - 3A62646C29C9ECD9007E8C07 /* PostHogTests-Bridging-Header.h */, 3A580B4229E489D000C5C6F3 /* URLSession+body.swift */, ); path = TestUtils; @@ -277,13 +276,12 @@ 3AA4C09B2988315D006C4731 /* Utils */ = { isa = PBXGroup; children = ( - 3AE3FB3829924CE100AFFC18 /* NSData+PHGGZIP.h */, - 3AE3FB3929924CE100AFFC18 /* NSData+PHGGZIP.m */, 3AE3FB422992985A00AFFC18 /* Reachability.swift */, 3AE3FB462992AB0000AFFC18 /* Hedgelog.swift */, 3A2BCF51299F7724008BB5F3 /* CodableUtils.swift */, 3A0F108429C9ABB6002C0084 /* ReadWriteLock.swift */, 3A0F108829C9BD76002C0084 /* Errors.swift */, + 690FF05E2AE7E2D400A0B06B /* Data+Gzip.swift */, ); path = Utils; sourceTree = ""; @@ -291,6 +289,7 @@ 3AC745AB296D6FE60025C109 = { isa = PBXGroup; children = ( + 690FF0532AE7DB3700A0B06B /* PostHogExampleWithSPM.xcodeproj */, 690FF02F2AE7C5BA00A0B06B /* PostHogExampleWithPods.xcodeproj */, 3AAFB13129C0C699004F485B /* Package.swift */, 3AC745B7296D6FE60025C109 /* PostHog */, @@ -359,6 +358,14 @@ name = Products; sourceTree = ""; }; + 690FF0542AE7DB3700A0B06B /* Products */ = { + isa = PBXGroup; + children = ( + 690FF0582AE7DB3700A0B06B /* PostHogExampleWithSPM.app */, + ); + name = Products; + sourceTree = ""; + }; 69261D152AD92D6C00232EC7 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -400,7 +407,6 @@ buildActionMask = 2147483647; files = ( 3AC745C6296D6FE60025C109 /* PostHog.h in Headers */, - 3A4F510D299A78E100B68D5E /* NSData+PHGGZIP.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -539,6 +545,10 @@ ProductGroup = 690FF0302AE7C5BA00A0B06B /* Products */; ProjectRef = 690FF02F2AE7C5BA00A0B06B /* PostHogExampleWithPods.xcodeproj */; }, + { + ProductGroup = 690FF0542AE7DB3700A0B06B /* Products */; + ProjectRef = 690FF0532AE7DB3700A0B06B /* PostHogExampleWithSPM.xcodeproj */; + }, ); projectRoot = ""; targets = ( @@ -558,6 +568,13 @@ remoteRef = 690FF0332AE7C5BB00A0B06B /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + 690FF0582AE7DB3700A0B06B /* PostHogExampleWithSPM.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + path = PostHogExampleWithSPM.app; + remoteRef = 690FF0572AE7DB3700A0B06B /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; /* End PBXReferenceProxy section */ /* Begin PBXResourcesBuildPhase section */ @@ -614,6 +631,7 @@ buildActionMask = 2147483647; files = ( 3A2BCF52299F7724008BB5F3 /* CodableUtils.swift in Sources */, + 690FF05F2AE7E2D400A0B06B /* Data+Gzip.swift in Sources */, 69261D1F2AD9681300232EC7 /* PostHogConsumerPayload.swift in Sources */, 69261D252AD9787A00232EC7 /* PostHogExtensions.swift in Sources */, 3AE3FB4E2993D1D600AFFC18 /* PostHogSessionManager.swift in Sources */, @@ -628,7 +646,6 @@ 3AE3FB3D29924E8200AFFC18 /* PostHogSDK.swift in Sources */, 3AE3FB3F29924F4F00AFFC18 /* PostHogConfig.swift in Sources */, 3AE3FB332991388500AFFC18 /* PostHogQueue.swift in Sources */, - 3AE3FB3B29924CE100AFFC18 /* NSData+PHGGZIP.m in Sources */, 69261D1B2AD9678C00232EC7 /* PostHogEvent.swift in Sources */, 3AE3FB472992AB0000AFFC18 /* Hedgelog.swift in Sources */, 69261D132AD5685B00232EC7 /* PostHogFeatureFlags.swift in Sources */, @@ -643,7 +660,6 @@ files = ( 3A62647529CB0168007E8C07 /* TestPostHog.swift in Sources */, 3A62646A29C9E385007E8C07 /* MockPostHogServer.swift in Sources */, - 3A62646F29C9ECDA007E8C07 /* NSData+PHGGUNZIPP.m in Sources */, 3A62647129CAF67B007E8C07 /* SessionManagerTest.swift in Sources */, 3AE3FB4B2993A68500AFFC18 /* StorageTest.swift in Sources */, 3A580B4329E489D000C5C6F3 /* URLSession+body.swift in Sources */, @@ -994,7 +1010,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.posthog.PostHogTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_OBJC_BRIDGING_HEADER = "PostHogTests/TestUtils/PostHogTests-Bridging-Header.h"; + SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1022,7 +1038,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.posthog.PostHogTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_OBJC_BRIDGING_HEADER = "PostHogTests/TestUtils/PostHogTests-Bridging-Header.h"; + SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TVOS_DEPLOYMENT_TARGET = 13.0; diff --git a/PostHog.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/PostHog.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index 69ada38e1..000000000 --- a/PostHog.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -1,95 +0,0 @@ -{ - "pins" : [ - { - "identity" : "cwlcatchexception", - "kind" : "remoteSourceControl", - "location" : "https://github.com/mattgallagher/CwlCatchException.git", - "state" : { - "revision" : "35f9e770f54ce62dd8526470f14c6e137cef3eea", - "version" : "2.1.1" - } - }, - { - "identity" : "cwlpreconditiontesting", - "kind" : "remoteSourceControl", - "location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git", - "state" : { - "revision" : "c21f7bab5ca8eee0a9998bbd17ca1d0eb45d4688", - "version" : "2.1.0" - } - }, - { - "identity" : "grmustache.swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/groue/GRMustache.swift", - "state" : { - "revision" : "edbe65da33671ca1e93e0751cbbeffc893b48da8", - "version" : "4.1.0" - } - }, - { - "identity" : "nimble", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Quick/Nimble.git", - "state" : { - "branch" : "main", - "revision" : "7d16c1cdf6fedfe559456bd933284e37cc481e13" - } - }, - { - "identity" : "ohhttpstubs", - "kind" : "remoteSourceControl", - "location" : "https://github.com/AliSoftware/OHHTTPStubs", - "state" : { - "revision" : "12f19662426d0434d6c330c6974d53e2eb10ecd9", - "version" : "9.1.0" - } - }, - { - "identity" : "quick", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Quick/Quick.git", - "state" : { - "branch" : "main", - "revision" : "1572f3972d0d6fe051743ccfb24a9f7c2ce45238" - } - }, - { - "identity" : "shock", - "kind" : "remoteSourceControl", - "location" : "https://github.com/justeat/Shock", - "state" : { - "revision" : "6cf1d47a09fa8bab09dd822fe15f77151ba0cc7b", - "version" : "6.2.0" - } - }, - { - "identity" : "swift-atomics", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-atomics.git", - "state" : { - "revision" : "ff3d2212b6b093db7f177d0855adbc4ef9c5f036", - "version" : "1.0.3" - } - }, - { - "identity" : "swift-collections", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-collections.git", - "state" : { - "revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2", - "version" : "1.0.4" - } - }, - { - "identity" : "swift-nio", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio", - "state" : { - "revision" : "9b2848d76f5caad08b97e71a04345aa5bdb23a06", - "version" : "2.49.0" - } - } - ], - "version" : 2 -} diff --git a/PostHog/PostHog.h b/PostHog/PostHog.h index 902bb76a1..c7a8d3e6f 100644 --- a/PostHog/PostHog.h +++ b/PostHog/PostHog.h @@ -7,9 +7,6 @@ #import -// do not use <> -// 'NSData+PHGGZIP.h' file not found with include; use "quotes" instead -#import "NSData+PHGGZIP.h" //! Project version number for PostHog. FOUNDATION_EXPORT double PostHogVersionNumber; diff --git a/PostHog/PostHogApi.swift b/PostHog/PostHogApi.swift index 6e5ee5c0f..c4fcdded1 100644 --- a/PostHog/PostHogApi.swift +++ b/PostHog/PostHogApi.swift @@ -53,9 +53,14 @@ class PostHogApi { return completion(PostHogBatchUploadInfo(statusCode: nil, error: error)) } - let gzippedPayload = NSData(data: data!).posthog_gzipped() + var gzippedPayload: Data? + do { + gzippedPayload = try data!.gzipped() + } catch { + return completion(PostHogBatchUploadInfo(statusCode: nil, error: error)) + } - URLSession(configuration: config).uploadTask(with: request, from: gzippedPayload) { data, response, error in + URLSession(configuration: config).uploadTask(with: request, from: gzippedPayload!) { data, response, error in if error != nil { return completion(PostHogBatchUploadInfo(statusCode: nil, error: error)) } diff --git a/PostHog/Utils/Data+Gzip.swift b/PostHog/Utils/Data+Gzip.swift new file mode 100644 index 000000000..1ff4d0f41 --- /dev/null +++ b/PostHog/Utils/Data+Gzip.swift @@ -0,0 +1,301 @@ +// +// Data+Gzip.swift +// +// https://github.com/1024jp/GzipSwift/blob/731037f6cc2be2ec01562f6597c1d0aa3fe6fd05/Sources/Gzip/Data%2BGzip.swift + +/* + The MIT License (MIT) + + © 2014-2023 1024jp + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +// issues importing scoped classes +//import struct Foundation.Data +import Foundation + +#if os(Linux) + import zlibLinux +#else + import zlib +#endif + +public enum Gzip { + /// Maximum value for windowBits (`MAX_WBITS`) + public static let maxWindowBits = MAX_WBITS +} + +/// Compression level whose rawValue is based on the zlib's constants. +public struct CompressionLevel: RawRepresentable, Sendable { + /// Compression level in the range of `0` (no compression) to `9` (maximum compression). + public let rawValue: Int32 + + public static let noCompression = Self(Z_NO_COMPRESSION) + public static let bestSpeed = Self(Z_BEST_SPEED) + public static let bestCompression = Self(Z_BEST_COMPRESSION) + + public static let defaultCompression = Self(Z_DEFAULT_COMPRESSION) + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public init(_ rawValue: Int32) { + self.rawValue = rawValue + } +} + +/// Errors on gzipping/gunzipping based on the zlib error codes. +public struct GzipError: Swift.Error, Sendable { + // cf. http://www.zlib.net/manual.html + + public enum Kind: Equatable, Sendable { + /// The stream structure was inconsistent. + /// + /// - underlying zlib error: `Z_STREAM_ERROR` (-2) + case stream + + /// The input data was corrupted + /// (input stream not conforming to the zlib format or incorrect check value). + /// + /// - underlying zlib error: `Z_DATA_ERROR` (-3) + case data + + /// There was not enough memory. + /// + /// - underlying zlib error: `Z_MEM_ERROR` (-4) + case memory + + /// No progress is possible or there was not enough room in the output buffer. + /// + /// - underlying zlib error: `Z_BUF_ERROR` (-5) + case buffer + + /// The zlib library version is incompatible with the version assumed by the caller. + /// + /// - underlying zlib error: `Z_VERSION_ERROR` (-6) + case version + + /// An unknown error occurred. + /// + /// - parameter code: return error by zlib + case unknown(code: Int) + } + + /// Error kind. + public let kind: Kind + + /// Returned message by zlib. + public let message: String + + init(code: Int32, msg: UnsafePointer?) { + message = msg.flatMap(String.init(validatingUTF8:)) ?? "Unknown gzip error" + kind = Kind(code: code) + } + + public var localizedDescription: String { + message + } +} + +private extension GzipError.Kind { + init(code: Int32) { + switch code { + case Z_STREAM_ERROR: + self = .stream + case Z_DATA_ERROR: + self = .data + case Z_MEM_ERROR: + self = .memory + case Z_BUF_ERROR: + self = .buffer + case Z_VERSION_ERROR: + self = .version + default: + self = .unknown(code: Int(code)) + } + } +} + +public extension Data { + /// Whether the receiver is compressed in gzip format. + var isGzipped: Bool { + starts(with: [0x1F, 0x8B]) // check magic number + } + + /// Create a new `Data` instance by compressing the receiver using zlib. + /// Throws an error if compression failed. + /// + /// The `wBits` parameter allows for managing the size of the history buffer. The possible values are: + /// + /// Value Window size logarithm Input + /// +9 to +15 Base 2 Includes zlib header and trailer + /// -9 to -15 Absolute value of wbits No header and trailer + /// +25 to +31 Low 4 bits of the value Includes gzip header and trailing checksum + /// + /// - Parameter level: Compression level. + /// - Parameter wBits: Manage the size of the history buffer. + /// - Returns: Gzip-compressed `Data` instance. + /// - Throws: `GzipError` + func gzipped(level: CompressionLevel = .defaultCompression, wBits: Int32 = Gzip.maxWindowBits + 16) throws -> Data { + guard !isEmpty else { + return Data() + } + + var stream = z_stream() + var status: Int32 + + status = deflateInit2_(&stream, level.rawValue, Z_DEFLATED, wBits, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY, ZLIB_VERSION, Int32(DataSize.stream)) + + guard status == Z_OK else { + // deflateInit2 returns: + // Z_VERSION_ERROR The zlib library version is incompatible with the version assumed by the caller. + // Z_MEM_ERROR There was not enough memory. + // Z_STREAM_ERROR A parameter is invalid. + + throw GzipError(code: status, msg: stream.msg) + } + + var data = Data(capacity: DataSize.chunk) + repeat { + if Int(stream.total_out) >= data.count { + data.count += DataSize.chunk + } + + let inputCount = count + let outputCount = data.count + + withUnsafeBytes { (inputPointer: UnsafeRawBufferPointer) in + stream.next_in = UnsafeMutablePointer(mutating: inputPointer.bindMemory(to: Bytef.self).baseAddress!).advanced(by: Int(stream.total_in)) + stream.avail_in = uInt(inputCount) - uInt(stream.total_in) + + data.withUnsafeMutableBytes { (outputPointer: UnsafeMutableRawBufferPointer) in + stream.next_out = outputPointer.bindMemory(to: Bytef.self).baseAddress!.advanced(by: Int(stream.total_out)) + stream.avail_out = uInt(outputCount) - uInt(stream.total_out) + + status = deflate(&stream, Z_FINISH) + + stream.next_out = nil + } + + stream.next_in = nil + } + + } while stream.avail_out == 0 && status != Z_STREAM_END + + guard deflateEnd(&stream) == Z_OK, status == Z_STREAM_END else { + throw GzipError(code: status, msg: stream.msg) + } + + data.count = Int(stream.total_out) + + return data + } + + /// Create a new `Data` instance by decompressing the receiver using zlib. + /// Throws an error if decompression failed. + /// + /// The `wBits` parameter allows for managing the size of the history buffer. The possible values are: + /// + /// Value Window size logarithm Input + /// +8 to +15 Base 2 Includes zlib header and trailer + /// -8 to -15 Absolute value of wbits Raw stream with no header and trailer + /// +24 to +31 = 16 + (8 to 15) Low 4 bits of the value Includes gzip header and trailer + /// +40 to +47 = 32 + (8 to 15) Low 4 bits of the value zlib or gzip format + /// + /// - Parameter wBits: Manage the size of the history buffer. + /// - Returns: Gzip-decompressed `Data` instance. + /// - Throws: `GzipError` + func gunzipped(wBits: Int32 = Gzip.maxWindowBits + 32) throws -> Data { + guard !isEmpty else { + return Data() + } + + var data = Data(capacity: count * 2) + var totalIn: uLong = 0 + var totalOut: uLong = 0 + + repeat { + var stream = z_stream() + var status: Int32 + + status = inflateInit2_(&stream, wBits, ZLIB_VERSION, Int32(DataSize.stream)) + + guard status == Z_OK else { + // inflateInit2 returns: + // Z_VERSION_ERROR The zlib library version is incompatible with the version assumed by the caller. + // Z_MEM_ERROR There was not enough memory. + // Z_STREAM_ERROR A parameters are invalid. + + throw GzipError(code: status, msg: stream.msg) + } + + repeat { + if Int(totalOut + stream.total_out) >= data.count { + data.count += count / 2 + } + + let inputCount = count + let outputCount = data.count + + withUnsafeBytes { (inputPointer: UnsafeRawBufferPointer) in + let inputStartPosition = totalIn + stream.total_in + stream.next_in = UnsafeMutablePointer(mutating: inputPointer.bindMemory(to: Bytef.self).baseAddress!).advanced(by: Int(inputStartPosition)) + stream.avail_in = uInt(inputCount) - uInt(inputStartPosition) + + data.withUnsafeMutableBytes { (outputPointer: UnsafeMutableRawBufferPointer) in + let outputStartPosition = totalOut + stream.total_out + stream.next_out = outputPointer.bindMemory(to: Bytef.self).baseAddress!.advanced(by: Int(outputStartPosition)) + stream.avail_out = uInt(outputCount) - uInt(outputStartPosition) + + status = inflate(&stream, Z_SYNC_FLUSH) + + stream.next_out = nil + } + + stream.next_in = nil + } + } while status == Z_OK + + totalIn += stream.total_in + + guard inflateEnd(&stream) == Z_OK, status == Z_STREAM_END else { + // inflate returns: + // Z_DATA_ERROR The input data was corrupted (input stream not conforming to the zlib format or incorrect check value). + // Z_STREAM_ERROR The stream structure was inconsistent (for example if next_in or next_out was NULL). + // Z_MEM_ERROR There was not enough memory. + // Z_BUF_ERROR No progress is possible or there was not enough room in the output buffer when Z_FINISH is used. + throw GzipError(code: status, msg: stream.msg) + } + + totalOut += stream.total_out + + } while totalIn < count + + data.count = Int(totalOut) + + return data + } +} + +private enum DataSize { + static let chunk = 1 << 14 + static let stream = MemoryLayout.size +} diff --git a/PostHog/Utils/NSData+PHGGZIP.h b/PostHog/Utils/NSData+PHGGZIP.h deleted file mode 100644 index 934dffa63..000000000 --- a/PostHog/Utils/NSData+PHGGZIP.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// GZIP.h -// -// Version 1.1.1 -// -// Created by Nick Lockwood on 03/06/2012. -// Copyright (C) 2012 Charcoal Design -// -// Distributed under the permissive zlib License -// Get the latest version from here: -// -// https://github.com/nicklockwood/GZIP -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// - - -#import - -extern void *_Nullable posthog_libzOpen(void); - - -@interface NSData (POSTHOG_GZIP) - -- (nullable NSData *)posthog_gzippedData; -- (BOOL)posthog_isGzippedData; - -@end diff --git a/PostHog/Utils/NSData+PHGGZIP.m b/PostHog/Utils/NSData+PHGGZIP.m deleted file mode 100644 index 569683a93..000000000 --- a/PostHog/Utils/NSData+PHGGZIP.m +++ /dev/null @@ -1,107 +0,0 @@ -// -// GZIP.m -// -// Version 1.1.1 -// -// Created by Nick Lockwood on 03/06/2012. -// Copyright (C) 2012 Charcoal Design -// -// Distributed under the permissive zlib License -// Get the latest version from here: -// -// https://github.com/nicklockwood/GZIP -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// - - -#import "NSData+PHGGZIP.h" -#import -#import - - -#pragma clang diagnostic ignored "-Wcast-qual" - -void *_Nullable posthog_libzOpen(void) -{ - static void *libz; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - libz = dlopen("/usr/lib/libz.dylib", RTLD_LAZY); - }); - return libz; -} - - -@implementation NSData (POSTHOG_GZIP) - -- (NSData *)posthog_gzippedDataWithCompressionLevel:(float)level -{ - if (self.length == 0 || [self posthog_isGzippedData]) { - return self; - } - - void *libz = posthog_libzOpen(); - int (*deflateInit2_)(z_streamp, int, int, int, int, int, const char *, int) = - (int (*)(z_streamp, int, int, int, int, int, const char *, int))dlsym(libz, "deflateInit2_"); - int (*deflate)(z_streamp, int) = (int (*)(z_streamp, int))dlsym(libz, "deflate"); - int (*deflateEnd)(z_streamp) = (int (*)(z_streamp))dlsym(libz, "deflateEnd"); - - z_stream stream; - stream.zalloc = Z_NULL; - stream.zfree = Z_NULL; - stream.opaque = Z_NULL; - stream.avail_in = (uint)self.length; - stream.next_in = (Bytef *)(void *)self.bytes; - stream.total_out = 0; - stream.avail_out = 0; - - static const NSUInteger ChunkSize = 16384; - - NSMutableData *output = nil; - int compression = (level < 0.0f) ? Z_DEFAULT_COMPRESSION : (int)(roundf(level * 9)); - if (deflateInit2(&stream, compression, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY) == Z_OK) { - output = [NSMutableData dataWithLength:ChunkSize]; - while (stream.avail_out == 0) { - if (stream.total_out >= output.length) { - output.length += ChunkSize; - } - stream.next_out = (uint8_t *)output.mutableBytes + stream.total_out; - stream.avail_out = (uInt)(output.length - stream.total_out); - deflate(&stream, Z_FINISH); - } - deflateEnd(&stream); - output.length = stream.total_out; - } - - return output; -} - -- (NSData *)posthog_gzippedData -{ - return [self posthog_gzippedDataWithCompressionLevel:-1.0f]; -} - -- (BOOL)posthog_isGzippedData -{ - const UInt8 *bytes = (const UInt8 *)self.bytes; - return (self.length >= 2 && bytes[0] == 0x1f && bytes[1] == 0x8b); -} - -@end diff --git a/PostHogExampleWithPods/PostHogExampleWithPods.xcodeproj/project.pbxproj b/PostHogExampleWithPods/PostHogExampleWithPods.xcodeproj/project.pbxproj index d9b7e46a7..5af157bec 100644 --- a/PostHogExampleWithPods/PostHogExampleWithPods.xcodeproj/project.pbxproj +++ b/PostHogExampleWithPods/PostHogExampleWithPods.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 690FF0262AE7C5BA00A0B06B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 690FF0252AE7C5BA00A0B06B /* Assets.xcassets */; }; 690FF0292AE7C5BA00A0B06B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 690FF0282AE7C5BA00A0B06B /* Preview Assets.xcassets */; }; 690FF0362AE7C61300A0B06B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 690FF0352AE7C61300A0B06B /* AppDelegate.swift */; }; + C0A3DD993CB1FDADCC4FA4A3 /* Pods_PostHogExampleWithPods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 232850674C6F805AF056B5E2 /* Pods_PostHogExampleWithPods.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -31,6 +32,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + C0A3DD993CB1FDADCC4FA4A3 /* Pods_PostHogExampleWithPods.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PostHogExampleWithSPM/.gitignore b/PostHogExampleWithSPM/.gitignore new file mode 100644 index 000000000..0023a5340 --- /dev/null +++ b/PostHogExampleWithSPM/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/project.pbxproj b/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/project.pbxproj new file mode 100644 index 000000000..4d16fe178 --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/project.pbxproj @@ -0,0 +1,377 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 60; + objects = { + +/* Begin PBXBuildFile section */ + 690FF0462AE7DB3600A0B06B /* PostHogExampleWithSPMApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 690FF0452AE7DB3600A0B06B /* PostHogExampleWithSPMApp.swift */; }; + 690FF0482AE7DB3600A0B06B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 690FF0472AE7DB3600A0B06B /* ContentView.swift */; }; + 690FF04A2AE7DB3700A0B06B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 690FF0492AE7DB3700A0B06B /* Assets.xcassets */; }; + 690FF04D2AE7DB3700A0B06B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 690FF04C2AE7DB3700A0B06B /* Preview Assets.xcassets */; }; + 690FF05A2AE7DD7500A0B06B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 690FF0592AE7DD7500A0B06B /* AppDelegate.swift */; }; + 690FF0612AE7E41800A0B06B /* PostHog in Frameworks */ = {isa = PBXBuildFile; productRef = 690FF0602AE7E41800A0B06B /* PostHog */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 690FF0422AE7DB3600A0B06B /* PostHogExampleWithSPM.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PostHogExampleWithSPM.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 690FF0452AE7DB3600A0B06B /* PostHogExampleWithSPMApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogExampleWithSPMApp.swift; sourceTree = ""; }; + 690FF0472AE7DB3600A0B06B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 690FF0492AE7DB3700A0B06B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 690FF04C2AE7DB3700A0B06B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 690FF0592AE7DD7500A0B06B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 690FF03F2AE7DB3600A0B06B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 690FF0612AE7E41800A0B06B /* PostHog in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 690FF0392AE7DB3600A0B06B = { + isa = PBXGroup; + children = ( + 690FF0442AE7DB3600A0B06B /* PostHogExampleWithSPM */, + 690FF0432AE7DB3600A0B06B /* Products */, + ); + sourceTree = ""; + }; + 690FF0432AE7DB3600A0B06B /* Products */ = { + isa = PBXGroup; + children = ( + 690FF0422AE7DB3600A0B06B /* PostHogExampleWithSPM.app */, + ); + name = Products; + sourceTree = ""; + }; + 690FF0442AE7DB3600A0B06B /* PostHogExampleWithSPM */ = { + isa = PBXGroup; + children = ( + 690FF0592AE7DD7500A0B06B /* AppDelegate.swift */, + 690FF0452AE7DB3600A0B06B /* PostHogExampleWithSPMApp.swift */, + 690FF0472AE7DB3600A0B06B /* ContentView.swift */, + 690FF0492AE7DB3700A0B06B /* Assets.xcassets */, + 690FF04B2AE7DB3700A0B06B /* Preview Content */, + ); + path = PostHogExampleWithSPM; + sourceTree = ""; + }; + 690FF04B2AE7DB3700A0B06B /* Preview Content */ = { + isa = PBXGroup; + children = ( + 690FF04C2AE7DB3700A0B06B /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 690FF0412AE7DB3600A0B06B /* PostHogExampleWithSPM */ = { + isa = PBXNativeTarget; + buildConfigurationList = 690FF0502AE7DB3700A0B06B /* Build configuration list for PBXNativeTarget "PostHogExampleWithSPM" */; + buildPhases = ( + 690FF03E2AE7DB3600A0B06B /* Sources */, + 690FF03F2AE7DB3600A0B06B /* Frameworks */, + 690FF0402AE7DB3600A0B06B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = PostHogExampleWithSPM; + packageProductDependencies = ( + 690FF0602AE7E41800A0B06B /* PostHog */, + ); + productName = PostHogExampleWithSPM; + productReference = 690FF0422AE7DB3600A0B06B /* PostHogExampleWithSPM.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 690FF03A2AE7DB3600A0B06B /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1500; + LastUpgradeCheck = 1500; + TargetAttributes = { + 690FF0412AE7DB3600A0B06B = { + CreatedOnToolsVersion = 15.0.1; + }; + }; + }; + buildConfigurationList = 690FF03D2AE7DB3600A0B06B /* Build configuration list for PBXProject "PostHogExampleWithSPM" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 690FF0392AE7DB3600A0B06B; + packageReferences = ( + 690FF05B2AE7E03B00A0B06B /* XCLocalSwiftPackageReference ".." */, + ); + productRefGroup = 690FF0432AE7DB3600A0B06B /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 690FF0412AE7DB3600A0B06B /* PostHogExampleWithSPM */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 690FF0402AE7DB3600A0B06B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 690FF04D2AE7DB3700A0B06B /* Preview Assets.xcassets in Resources */, + 690FF04A2AE7DB3700A0B06B /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 690FF03E2AE7DB3600A0B06B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 690FF05A2AE7DD7500A0B06B /* AppDelegate.swift in Sources */, + 690FF0482AE7DB3600A0B06B /* ContentView.swift in Sources */, + 690FF0462AE7DB3600A0B06B /* PostHogExampleWithSPMApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 690FF04E2AE7DB3700A0B06B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 690FF04F2AE7DB3700A0B06B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 690FF0512AE7DB3700A0B06B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"PostHogExampleWithSPM/Preview Content\""; + DEVELOPMENT_TEAM = PNC2XCH2XP; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.posthog.PostHogExampleWithSPM; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 690FF0522AE7DB3700A0B06B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"PostHogExampleWithSPM/Preview Content\""; + DEVELOPMENT_TEAM = PNC2XCH2XP; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.posthog.PostHogExampleWithSPM; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 690FF03D2AE7DB3600A0B06B /* Build configuration list for PBXProject "PostHogExampleWithSPM" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 690FF04E2AE7DB3700A0B06B /* Debug */, + 690FF04F2AE7DB3700A0B06B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 690FF0502AE7DB3700A0B06B /* Build configuration list for PBXNativeTarget "PostHogExampleWithSPM" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 690FF0512AE7DB3700A0B06B /* Debug */, + 690FF0522AE7DB3700A0B06B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCLocalSwiftPackageReference section */ + 690FF05B2AE7E03B00A0B06B /* XCLocalSwiftPackageReference ".." */ = { + isa = XCLocalSwiftPackageReference; + relativePath = ..; + }; +/* End XCLocalSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 690FF0602AE7E41800A0B06B /* PostHog */ = { + isa = XCSwiftPackageProductDependency; + productName = PostHog; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 690FF03A2AE7DB3600A0B06B /* Project object */; +} diff --git a/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..919434a62 --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/xcshareddata/xcschemes/PostHogExampleWithSPM.xcscheme b/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/xcshareddata/xcschemes/PostHogExampleWithSPM.xcscheme new file mode 100644 index 000000000..d112efb71 --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM.xcodeproj/xcshareddata/xcschemes/PostHogExampleWithSPM.xcscheme @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PostHogExampleWithSPM/PostHogExampleWithSPM/AppDelegate.swift b/PostHogExampleWithSPM/PostHogExampleWithSPM/AppDelegate.swift new file mode 100644 index 000000000..178f4d40f --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM/AppDelegate.swift @@ -0,0 +1,34 @@ +// +// AppDelegate.swift +// PostHogExampleWithPods +// +// Created by Manoel Aranda Neto on 24.10.23. +// +import Foundation +import PostHog +import UIKit + +class AppDelegate: NSObject, UIApplicationDelegate { + func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { + let defaultCenter = NotificationCenter.default + + defaultCenter.addObserver(self, + selector: #selector(receiveFeatureFlags), + name: PostHogSDK.didReceiveFeatureFlags, + object: nil) + + let config = PostHogConfig( + apiKey: "_6SG-F7I1vCuZ-HdJL3VZQqjBlaSb1_20hDPwqMNnGI" + ) + + PostHogSDK.shared.setup(config) + PostHogSDK.shared.debug() + PostHogSDK.shared.capture("Event from SPM example!") + + return true + } + + @objc func receiveFeatureFlags() { + print("receiveFeatureFlags") + } +} diff --git a/PostHogExampleWithSPM/PostHogExampleWithSPM/Assets.xcassets/AccentColor.colorset/Contents.json b/PostHogExampleWithSPM/PostHogExampleWithSPM/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 000000000..eb8789700 --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PostHogExampleWithSPM/PostHogExampleWithSPM/Assets.xcassets/AppIcon.appiconset/Contents.json b/PostHogExampleWithSPM/PostHogExampleWithSPM/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..13613e3ee --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM/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/PostHogExampleWithSPM/PostHogExampleWithSPM/Assets.xcassets/Contents.json b/PostHogExampleWithSPM/PostHogExampleWithSPM/Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PostHogExampleWithSPM/PostHogExampleWithSPM/ContentView.swift b/PostHogExampleWithSPM/PostHogExampleWithSPM/ContentView.swift new file mode 100644 index 000000000..dd9fd5444 --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM/ContentView.swift @@ -0,0 +1,24 @@ +// +// ContentView.swift +// PostHogExampleWithSPM +// +// Created by Manoel Aranda Neto on 24.10.23. +// + +import SwiftUI + +struct ContentView: View { + var body: some View { + VStack { + Image(systemName: "globe") + .imageScale(.large) + .foregroundStyle(.tint) + Text("Hello, world!") + } + .padding() + } +} + +#Preview { + ContentView() +} diff --git a/PostHogExampleWithSPM/PostHogExampleWithSPM/PostHogExampleWithSPMApp.swift b/PostHogExampleWithSPM/PostHogExampleWithSPM/PostHogExampleWithSPMApp.swift new file mode 100644 index 000000000..74da7f57d --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM/PostHogExampleWithSPMApp.swift @@ -0,0 +1,19 @@ +// +// PostHogExampleWithSPMApp.swift +// PostHogExampleWithSPM +// +// Created by Manoel Aranda Neto on 24.10.23. +// + +import SwiftUI + +@main +struct PostHogExampleWithSPMApp: App { + @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate + + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/PostHogExampleWithSPM/PostHogExampleWithSPM/Preview Content/Preview Assets.xcassets/Contents.json b/PostHogExampleWithSPM/PostHogExampleWithSPM/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/PostHogExampleWithSPM/PostHogExampleWithSPM/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PostHogExampleWithSPM/README.md b/PostHogExampleWithSPM/README.md new file mode 100644 index 000000000..4de7095df --- /dev/null +++ b/PostHogExampleWithSPM/README.md @@ -0,0 +1,28 @@ +# Example with SPM + +This is an example of how to use the PostHog iOS SDK with SPM. + +## Installation + +1. Install Xcode if you haven't already: + +Follow steps from the [Xcode docs](https://developer.apple.com/xcode/resources/). + +## Add a SP dependency to the project via Xcode + +1. Click on the project in the Project Navigator. +2. Select the project in the Project and Targets list. +3. Select the General tab. +4. Scroll down to the Frameworks and Libraries section. +5. Click the + button. +6. Click Add Other... +7. Click Add Package Dependency +8. Enter the URL of the PostHog SDK repo or the local path to the repo. + +## Import the PostHog package + +```swift +import PostHog +``` + +And run the project. diff --git a/PostHogTests/PostHogTest.swift b/PostHogTests/PostHogTest.swift index e75d066d6..c40446b4a 100644 --- a/PostHogTests/PostHogTest.swift +++ b/PostHogTests/PostHogTest.swift @@ -1,5 +1,6 @@ import Nimble import Quick +import Foundation @testable import PostHog @@ -51,8 +52,6 @@ class PostHogTest: QuickSpec { expect(anonymousId) == otherAnonymousId expect(distinctId) == otherDistinctId - expect(sessionId) != otherSessionId - expect(refreshedSessionId) == otherSessionId } // it("fires Application Opened for UIApplicationDidFinishLaunching") { diff --git a/PostHogTests/SessionManagerTest.swift b/PostHogTests/SessionManagerTest.swift index 0d19dd740..60f051fa9 100644 --- a/PostHogTests/SessionManagerTest.swift +++ b/PostHogTests/SessionManagerTest.swift @@ -8,6 +8,7 @@ import Nimble @testable import PostHog import Quick +import Foundation class SessionManagerTest: QuickSpec { override func spec() { diff --git a/PostHogTests/StorageTest.swift b/PostHogTests/StorageTest.swift index 87f726203..97bc0f1d3 100644 --- a/PostHogTests/StorageTest.swift +++ b/PostHogTests/StorageTest.swift @@ -7,6 +7,7 @@ import Nimble import Quick +import Foundation @testable import PostHog diff --git a/PostHogTests/TestUtils/MockPostHogServer.swift b/PostHogTests/TestUtils/MockPostHogServer.swift index 3fc605a91..0c4b70ad2 100644 --- a/PostHogTests/TestUtils/MockPostHogServer.swift +++ b/PostHogTests/TestUtils/MockPostHogServer.swift @@ -78,8 +78,12 @@ class MockPostHogServer { } func parseBatchRequest(_ context: URLRequest) -> [String: Any]? { - let data = NSData(data: context.body()!) - let unzippedData = data.posthog_gunzipped() + var unzippedData: Data? + do { + unzippedData = try context.body()!.gzipped() + } catch { + // its ok + } return try? JSONSerialization.jsonObject(with: unzippedData!, options: []) as? [String: Any] } diff --git a/PostHogTests/TestUtils/NSData+PHGGUNZIPP.h b/PostHogTests/TestUtils/NSData+PHGGUNZIPP.h deleted file mode 100644 index 409df7162..000000000 --- a/PostHogTests/TestUtils/NSData+PHGGUNZIPP.h +++ /dev/null @@ -1,10 +0,0 @@ -// https://github.com/nicklockwood/GZIP/blob/master/GZIP/NSData%2BGZIP.m - -#import - - -@interface NSData (PHGGUNZIPP) - -- (NSData *_Nullable)posthog_gunzippedData; - -@end diff --git a/PostHogTests/TestUtils/NSData+PHGGUNZIPP.m b/PostHogTests/TestUtils/NSData+PHGGUNZIPP.m deleted file mode 100644 index 37eab890a..000000000 --- a/PostHogTests/TestUtils/NSData+PHGGUNZIPP.m +++ /dev/null @@ -1,54 +0,0 @@ -// https://github.com/nicklockwood/GZIP/blob/master/GZIP/NSData%2BGZIP.m - -#import -#import -#import "NSData+PHGGZIP.h" -#import "NSData+PHGGUNZIPP.h" - - -@implementation NSData (PHGGUNZIPP) - -- (NSData *)posthog_gunzippedData -{ - if (self.length == 0 || ![self posthog_isGzippedData]) { - return self; - } - - void *libz = posthog_libzOpen(); - int (*inflateInit2_)(z_streamp, int, const char *, int) = - (int (*)(z_streamp, int, const char *, int))dlsym(libz, "inflateInit2_"); - int (*inflate)(z_streamp, int) = (int (*)(z_streamp, int))dlsym(libz, "inflate"); - int (*inflateEnd)(z_streamp) = (int (*)(z_streamp))dlsym(libz, "inflateEnd"); - - z_stream stream; - stream.zalloc = Z_NULL; - stream.zfree = Z_NULL; - stream.avail_in = (uint)self.length; - stream.next_in = (Bytef *)self.bytes; - stream.total_out = 0; - stream.avail_out = 0; - - NSMutableData *output = nil; - if (inflateInit2(&stream, 47) == Z_OK) { - int status = Z_OK; - output = [NSMutableData dataWithCapacity:self.length * 2]; - while (status == Z_OK) { - if (stream.total_out >= output.length) { - output.length += self.length / 2; - } - stream.next_out = (uint8_t *)output.mutableBytes + stream.total_out; - stream.avail_out = (uInt)(output.length - stream.total_out); - status = inflate(&stream, Z_SYNC_FLUSH); - } - if (inflateEnd(&stream) == Z_OK) { - if (status == Z_STREAM_END) { - output.length = stream.total_out; - } - } - } - - return output; -} - - -@end diff --git a/PostHogTests/TestUtils/PostHogTests-Bridging-Header.h b/PostHogTests/TestUtils/PostHogTests-Bridging-Header.h deleted file mode 100644 index 47c5a7b89..000000000 --- a/PostHogTests/TestUtils/PostHogTests-Bridging-Header.h +++ /dev/null @@ -1,5 +0,0 @@ -// -// Use this file to import your target's public headers that you would like to expose to Swift. -// - -#import "NSData+PHGGUNZIPP.h"