Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Jan 10, 2024
1 parent 90bdcf4 commit 4a206d3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
12 changes: 1 addition & 11 deletions PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ let maxRetryDelay = 30.0
private static var apiKeys = Set<String>()
private var capturedAppInstalled = false
private var appFromBackground = false
private var ignoreFirstAppFromBackground = true

@objc public static let shared: PostHogSDK = {
let instance = PostHogSDK(PostHogConfig(apiKey: ""))
Expand Down Expand Up @@ -651,7 +650,7 @@ let maxRetryDelay = 30.0
object: nil)
defaultCenter.addObserver(self,
selector: #selector(captureAppOpenedFromBackground),
name: UIApplication.willEnterForegroundNotification,
name: UIApplication.didBecomeActiveNotification,
object: nil)
#endif
}
Expand Down Expand Up @@ -739,14 +738,6 @@ let maxRetryDelay = 30.0
}

@objc func captureAppOpenedFromBackground() {
// when the app is opened for the first time, the OS sends 2 notifications, didFinishLaunchingNotification
// and willEnterForegroundNotification, but we only want to log one "Application Opened" event.
// All the following app opened from background events should be logged normally.
if ignoreFirstAppFromBackground {
ignoreFirstAppFromBackground = false
return
}

var props: [String: Any] = [:]
props["from_background"] = appFromBackground

Expand All @@ -763,7 +754,6 @@ let maxRetryDelay = 30.0
}

captureAppInstalled()
captureAppOpened()
}

@objc func captureAppBackgrounded() {
Expand Down
15 changes: 0 additions & 15 deletions PostHogTests/PostHogSDKTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,9 @@ class PostHogSDKTest: QuickSpec {
sut.close()
}

it("ignore first AppOpenedFromBackground") {
let sut = self.getSut()

sut.captureAppOpenedFromBackground()

expect(server.batchRequests.count) == 0

sut.reset()
sut.close()
}

it("capture AppOpenedFromBackground from_background should be false") {
let sut = self.getSut()

// the first call is just to flip the ignoreFirstAppFromBackground flag
sut.captureAppOpenedFromBackground()
sut.captureAppOpenedFromBackground()

let events = getBatchedEvents(server)
Expand All @@ -374,8 +361,6 @@ class PostHogSDKTest: QuickSpec {
it("capture AppOpenedFromBackground from_background should be true") {
let sut = self.getSut(flushAt: 2)

// the first call is just to flip the ignoreFirstAppFromBackground flag
sut.captureAppOpenedFromBackground()
sut.captureAppOpenedFromBackground()
sut.captureAppOpenedFromBackground()

Expand Down

0 comments on commit 4a206d3

Please sign in to comment.