@@ -50,19 +50,8 @@ + (NSString *)mExternalIdAuthToken;
5050
5151@implementation OneSignalTracker
5252
53- static NSTimeInterval lastOpenedTime;
5453static BOOL lastOnFocusWasToBackground = YES ;
5554
56- + (void )resetLocals {
57- [OSFocusTimeProcessorFactory resetUnsentActiveTime ];
58- lastOpenedTime = 0 ;
59- lastOnFocusWasToBackground = YES ;
60- }
61-
62- + (void )setLastOpenedTime : (NSTimeInterval )lastOpened {
63- lastOpenedTime = lastOpened;
64- }
65-
6655+ (void )onFocus : (BOOL )toBackground {
6756 // return if the user has not granted privacy permissions
6857 if ([OSPrivacyConsentController requiresUserPrivacyConsent ])
@@ -88,7 +77,7 @@ + (void)applicationBecameActive {
8877 if (OSSessionManager.sharedSessionManager .appEntryState != NOTIFICATION_CLICK)
8978 OSSessionManager.sharedSessionManager .appEntryState = APP_OPEN;
9079
91- lastOpenedTime = [ NSDate date ]. timeIntervalSince1970 ;
80+ [OSSessionManager.sharedSessionManager setLastOpenedTime: [[ NSDate date ] timeIntervalSince1970 ]] ;
9281
9382 // on_session tracking when resumming app.
9483 if ([OneSignal shouldStartNewSession ])
@@ -104,7 +93,7 @@ + (void)applicationBackgrounded {
10493 [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: @" Application Backgrounded started" ];
10594 [self updateLastClosedTime ];
10695
107- let timeElapsed = [self getTimeFocusedElapsed ];
96+ let timeElapsed = [OSSessionManager.sharedSessionManager getTimeFocusedElapsed ];
10897 if (timeElapsed < -1 )
10998 return ;
11099
@@ -124,7 +113,7 @@ + (void)applicationBackgrounded {
124113// The on_focus call is made right away.
125114+ (void )onSessionEnded : (NSArray <OSInfluence *> *)lastInfluences {
126115 [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: @" onSessionEnded started" ];
127- let timeElapsed = [self getTimeFocusedElapsed ];
116+ let timeElapsed = [OSSessionManager.sharedSessionManager getTimeFocusedElapsed ];
128117 let focusCallParams = [self createFocusCallParams: lastInfluences onSessionEnded: true ];
129118 let timeProcessor = [OSFocusTimeProcessorFactory createTimeProcessorWithInfluences: lastInfluences focusEventType: END_SESSION];
130119
@@ -141,7 +130,7 @@ + (void)onSessionEnded:(NSArray<OSInfluence *> *)lastInfluences {
141130}
142131
143132+ (OSFocusCallParams *)createFocusCallParams : (NSArray <OSInfluence *> *)lastInfluences onSessionEnded : (BOOL )onSessionEnded {
144- let timeElapsed = [self getTimeFocusedElapsed ];
133+ let timeElapsed = [OSSessionManager.sharedSessionManager getTimeFocusedElapsed ];
145134 NSMutableArray <OSFocusInfluenceParam *> *focusInfluenceParams = [NSMutableArray new ];
146135
147136 for (OSInfluence *influence in lastInfluences) {
@@ -159,20 +148,6 @@ + (OSFocusCallParams *)createFocusCallParams:(NSArray<OSInfluence *> *)lastInflu
159148 onSessionEnded: onSessionEnded];
160149}
161150
162- + (NSTimeInterval )getTimeFocusedElapsed {
163- if (!lastOpenedTime)
164- return -1 ;
165-
166- let now = [NSDate date ].timeIntervalSince1970 ;
167- let timeElapsed = now - (int )(lastOpenedTime + 0.5 );
168-
169- // Time is invalid if below 1 or over a day
170- if (timeElapsed < 0 || timeElapsed > 86400 )
171- return -1 ;
172-
173- return timeElapsed;
174- }
175-
176151+ (void )updateLastClosedTime {
177152 let now = [NSDate date ].timeIntervalSince1970 ;
178153 [OneSignalUserDefaults.initStandard saveDoubleForKey: OSUD_APP_LAST_CLOSED_TIME withValue: now];
0 commit comments