@@ -41,6 +41,7 @@ @implementation OSSessionManager
4141static OSSessionManager *_sessionManager;
4242
4343NSDate *_sessionLaunchTime;
44+ AppEntryAction _appEntryState = APP_CLOSE;
4445
4546+ (OSSessionManager*)sharedSessionManager {
4647 if (!_sessionManager)
@@ -52,6 +53,14 @@ + (void)resetSharedSessionManager {
5253 _sessionManager = nil ;
5354}
5455
56+ - (AppEntryAction)appEntryState {
57+ return _appEntryState;
58+ }
59+
60+ - (void )setAppEntryState : (AppEntryAction)appEntryState {
61+ _appEntryState = appEntryState;
62+ }
63+
5564- (instancetype _Nonnull)init : (id <SessionStatusDelegate>)delegate withTrackerFactory : (OSTrackerFactory *)trackerFactory {
5665 if (self = [super init ]) {
5766 _delegate = delegate;
@@ -75,11 +84,11 @@ - (void)initSessionFromCache {
7584 [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: [NSString stringWithFormat: @" SessionManager restored from cache with influences: %@ " , [self getInfluences ].description]];
7685}
7786
78- - (void )restartSessionIfNeeded : (AppEntryAction) entryAction {
79- NSArray <OSChannelTracker *> *channelTrackers = [_trackerFactory channelsToResetByEntryAction: entryAction ];
87+ - (void )restartSessionIfNeeded {
88+ NSArray <OSChannelTracker *> *channelTrackers = [_trackerFactory channelsToResetByEntryAction: _appEntryState ];
8089 NSMutableArray <OSInfluence *> *updatedInfluences = [NSMutableArray new ];
8190
82- [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: [NSString stringWithFormat: @" OneSignal SessionManager restartSessionIfNeeded with entryAction:: %u channelTrackers: %@ " , entryAction , channelTrackers.description]];
91+ [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: [NSString stringWithFormat: @" OneSignal SessionManager restartSessionIfNeeded with entryAction:: %u channelTrackers: %@ " , _appEntryState , channelTrackers.description]];
8392
8493 for (OSChannelTracker *channelTracker in channelTrackers) {
8594 NSArray *lastIds = [channelTracker lastReceivedIds ];
@@ -134,12 +143,13 @@ - (void)onNotificationReceived:(NSString *)notificationId {
134143}
135144
136145- (void )onDirectInfluenceFromNotificationOpen : (AppEntryAction)entryAction withNotificationId : (NSString *)directNotificationId {
146+ _appEntryState = entryAction;
137147 [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: [NSString stringWithFormat: @" OneSignal SessionManager onDirectInfluenceFromNotificationOpen notificationId: %@ " , directNotificationId]];
138148
139149 if (!directNotificationId || directNotificationId.length == 0 )
140150 return ;
141151
142- [self attemptSessionUpgrade: entryAction withDirectId : directNotificationId];
152+ [self attemptSessionUpgradeWithDirectId : directNotificationId];
143153}
144154
145155/*
@@ -150,15 +160,15 @@ - (void)onDirectInfluenceFromNotificationOpen:(AppEntryAction)entryAction withNo
150160 * INDIRECT -> DIRECT
151161 * DIRECT -> DIRECT
152162 */
153- - (void )attemptSessionUpgrade : (AppEntryAction) entryAction {
154- [self attemptSessionUpgrade: entryAction withDirectId :nil ];
163+ - (void )attemptSessionUpgrade {
164+ [self attemptSessionUpgradeWithDirectId :nil ];
155165}
156166
157- - (void )attemptSessionUpgrade : (AppEntryAction) entryAction withDirectId : (NSString *)directId {
158- [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: [NSString stringWithFormat: @" OneSignal SessionManager attemptSessionUpgrade with entryAction: %u " , entryAction ]];
167+ - (void )attemptSessionUpgradeWithDirectId : (NSString *)directId {
168+ [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: [NSString stringWithFormat: @" OneSignal SessionManager attemptSessionUpgrade with entryAction: %u " , _appEntryState ]];
159169
160- OSChannelTracker *channelTrackerByAction = [_trackerFactory channelByEntryAction: entryAction ];
161- NSArray <OSChannelTracker *> *channelTrackersToReset = [_trackerFactory channelsToResetByEntryAction: entryAction ];
170+ OSChannelTracker *channelTrackerByAction = [_trackerFactory channelByEntryAction: _appEntryState ];
171+ NSArray <OSChannelTracker *> *channelTrackersToReset = [_trackerFactory channelsToResetByEntryAction: _appEntryState ];
162172 NSMutableArray <OSInfluence *> *influencesToEnd = [NSMutableArray new ];
163173 OSInfluence *lastInfluence = nil ;
164174
@@ -190,7 +200,7 @@ - (void)attemptSessionUpgrade:(AppEntryAction)entryAction withDirectId:(NSString
190200 if (channelTracker.influenceType == UNATTRIBUTED) {
191201 NSArray *lastIds = [channelTracker lastReceivedIds ];
192202 // There are new ids for attribution and the application was open again without resetting session
193- if (lastIds.count > 0 && entryAction != APP_CLOSE) {
203+ if (lastIds.count > 0 && _appEntryState != APP_CLOSE) {
194204 // Save influence to ended it later if needed
195205 // This influence will be unattributed
196206 OSInfluence *influence = [channelTracker currentSessionInfluence ];
0 commit comments