diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m index d8e731cee3..47ae5326fa 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m @@ -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"; @@ -348,6 +349,7 @@ @implementation FBSDKAppEvents #endif NSString *_userID; BOOL _isUnityInit; + UIApplicationState _applicationState; } #pragma mark - Object Lifecycle @@ -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 @@ -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 @@ -1277,6 +1289,8 @@ - (void)flushTimerFired:(id)arg - (void)applicationDidBecomeActive { + _applicationState = UIApplicationStateActive; + [FBSDKAppEventsUtility ensureOnMainThread:NSStringFromSelector(_cmd) className:NSStringFromClass([self class])]; [self checkPersistedEvents]; @@ -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