Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 6364a2c

Browse files
authored
Add pixel to check if in between double background willEnterForeground is called (#3788)
Task/Issue URL: https://app.asana.com/0/0/1209098575913251/f
1 parent faa179b commit 6364a2c

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎Core/Pixel.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ public struct PixelParameters {
166166

167167
public static let appState = "state"
168168
public static let appEvent = "event"
169+
170+
public static let didCallWillEnterForeground = "didCallWillEnterForeground"
169171
}
170172

171173
public struct PixelValues {

‎Core/PixelEvent.swift‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,8 @@ extension Pixel {
974974

975975
// MARK: Lifecycle
976976
case appDidTransitionToUnexpectedState
977+
case appDidConsecutivelyBackground
978+
977979
}
978980

979981
}
@@ -1945,6 +1947,7 @@ extension Pixel.Event {
19451947

19461948
// MARK: Lifecycle
19471949
case .appDidTransitionToUnexpectedState: return "m_debug_app-did-transition-to-unexpected-state-2"
1950+
case .appDidConsecutivelyBackground: return "m_debug_app-did-consecutively-background-2"
19481951

19491952
}
19501953
}

‎DuckDuckGo/AppDelegate.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ protocol DDGApp {
6767
}
6868
}()
6969

70+
var didCallWillEnterForeground: Bool = false
71+
7072
override init() {
7173
super.init()
7274
realDelegate.initialize()
@@ -77,6 +79,7 @@ protocol DDGApp {
7779
}
7880

7981
func applicationDidBecomeActive(_ application: UIApplication) {
82+
didCallWillEnterForeground = false
8083
realDelegate.applicationDidBecomeActive?(application)
8184
}
8285

@@ -85,6 +88,7 @@ protocol DDGApp {
8588
}
8689

8790
func applicationWillEnterForeground(_ application: UIApplication) {
91+
didCallWillEnterForeground = true
8892
realDelegate.applicationWillEnterForeground?(application)
8993
}
9094

‎DuckDuckGo/AppLifecycle/AppStateTransitions.swift‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ extension Background {
104104
urlToOpen = url
105105
return self
106106
case .backgrounding:
107+
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
108+
Pixel.fire(pixel: .appDidConsecutivelyBackground, withAdditionalParameters: [
109+
PixelParameters.didCallWillEnterForeground: appDelegate.didCallWillEnterForeground.description
110+
])
111+
appDelegate.didCallWillEnterForeground = false
112+
}
107113
run()
108114
return self
109115
case .handleShortcutItem(let shortcutItem):

0 commit comments

Comments
 (0)