Skip to content

Commit 6dd748d

Browse files
carloskelly13bsneed
authored andcommitted
Add iOS Backgrounded Event. (#831)
* Add iOS Backgrounded Event. * Bump Xcode CI version * Bump pods * Updated properties * Simplified App Backgrounded call * Fixed test since we dropped the param. * Reverted xcode CI version number
1 parent d560945 commit 6dd748d

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Analytics/Classes/SEGAnalytics.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ - (void)handleAppStateNotification:(NSNotification *)note
111111
[self _applicationDidFinishLaunchingWithOptions:note.userInfo];
112112
} else if ([note.name isEqualToString:UIApplicationWillEnterForegroundNotification]) {
113113
[self _applicationWillEnterForeground];
114+
} else if ([note.name isEqualToString: UIApplicationDidEnterBackgroundNotification]) {
115+
[self _applicationDidEnterBackground];
114116
}
115117
}
116118

@@ -167,15 +169,19 @@ - (void)_applicationWillEnterForeground
167169
if (!self.configuration.trackApplicationLifecycleEvents) {
168170
return;
169171
}
170-
NSString *currentVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
171-
NSString *currentBuild = [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];
172172
[self track:@"Application Opened" properties:@{
173173
@"from_background" : @YES,
174-
@"version" : currentVersion ?: @"",
175-
@"build" : currentBuild ?: @"",
176174
}];
177175
}
178176

177+
- (void)_applicationDidEnterBackground
178+
{
179+
if (!self.configuration.trackApplicationLifecycleEvents) {
180+
return;
181+
}
182+
[self track: @"Application Backgrounded"];
183+
}
184+
179185

180186
#pragma mark - Public API
181187

AnalyticsTests/AnalyticsTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ class AnalyticsTests: QuickSpec {
102102
expect(event?.event) == "Application Opened"
103103
expect(event?.properties?["from_background"] as? Bool) == true
104104
}
105+
106+
it("fires Application Backgrounded during UIApplicationDidEnterBackground") {
107+
testMiddleware.swallowEvent = true
108+
NotificationCenter.default.post(name: .UIApplicationDidEnterBackground, object: testApplication)
109+
let event = testMiddleware.lastContext?.payload as? SEGTrackPayload
110+
expect(event?.event) == "Application Backgrounded"
111+
}
105112

106113
it("flushes when UIApplicationDidEnterBackgroundNotification is fired") {
107114
analytics.track("test")

Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
target 'AnalyticsTests' do
22
platform :ios, '11'
3-
3+
44
use_frameworks!
5-
5+
66
pod 'Quick', '~> 1.2.0'
77
pod 'Nimble', '~> 7.3.4'
88
pod 'Nocilla', '~> 0.11.0'

0 commit comments

Comments
 (0)