Skip to content

Commit

Permalink
Add _inBackground for app events to indicate whether the events were …
Browse files Browse the repository at this point in the history
…logged when app in background mode

Summary: As title

Reviewed By: YOUDAN

Differential Revision: D14576211

fbshipit-source-id: 1217b0fbbe94d6d5f604bf8943e8d61b40a9f6c3
  • Loading branch information
dreamolight authored and facebook-github-bot committed Mar 29, 2019
1 parent cac0dc7 commit c6a2a1b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
NSString *const FBSDKAppEventParameterLogTime = @"_logTime";
NSString *const FBSDKAppEventParameterEventName = @"_eventName";
NSString *const FBSDKAppEventParameterImplicitlyLogged = @"_implicitlyLogged";
NSString *const FBSDKAppEventParameterInBackground = @"_inBackground";

NSString *const FBSDKAppEventParameterLiveStreamingPrevStatus = @"live_streaming_prev_status";
NSString *const FBSDKAppEventParameterLiveStreamingStatus = @"live_streaming_status";
Expand Down Expand Up @@ -348,6 +349,7 @@ @implementation FBSDKAppEvents
#endif
NSString *_userID;
BOOL _isUnityInit;
UIApplicationState _applicationState;
}

#pragma mark - Object Lifecycle
Expand Down Expand Up @@ -397,6 +399,12 @@ - (void)registerNotifications {
selector:@selector(applicationDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:NULL];

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(applicationDidEnterBackground)
name:UIApplicationDidEnterBackgroundNotification
object:NULL];
}

- (void)dealloc
Expand Down Expand Up @@ -1047,6 +1055,10 @@ - (void)instanceLogEvent:(FBSDKAppEventName)eventName
eventDictionary[FBSDKAppEventParameterImplicitlyLogged] = @"1";
}

if (_applicationState == UIApplicationStateBackground) {
eventDictionary[FBSDKAppEventParameterInBackground] = @"1";
}

NSString *currentViewControllerName;
if ([NSThread isMainThread]) {
// We only collect the view controller when on the main thread, as the behavior off
Expand Down Expand Up @@ -1277,6 +1289,8 @@ - (void)flushTimerFired:(id)arg

- (void)applicationDidBecomeActive
{
_applicationState = UIApplicationStateActive;

[FBSDKAppEventsUtility ensureOnMainThread:NSStringFromSelector(_cmd) className:NSStringFromClass([self class])];

[self checkPersistedEvents];
Expand All @@ -1285,6 +1299,11 @@ - (void)applicationDidBecomeActive
[FBSDKTimeSpentData restore:NO];
}

- (void)applicationDidEnterBackground
{
_applicationState = UIApplicationStateBackground;
}

- (void)applicationMovingFromActiveStateOrTerminating
{
// When moving from active state, we don't have time to wait for the result of a flush, so
Expand Down

0 comments on commit c6a2a1b

Please sign in to comment.