Skip to content

Commit

Permalink
Merge pull request #1327 from OneSignal/v5/fix/direct_id_crash
Browse files Browse the repository at this point in the history
[v5] Fix crash with direct influence but nil direct id
  • Loading branch information
nan-li authored Oct 30, 2023
2 parents 00a9990 + 4de4431 commit f358fc1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ - (OSInfluence *)currentSessionInfluence {

if (_influenceType == DIRECT) {
if ([self isDirectSessionEnabled]) {
NSArray *ids = [NSArray arrayWithObject:_directId];
builder.ids = ids;
builder.influenceType = DIRECT;
if (_directId) {
NSArray *ids = [NSArray arrayWithObject:_directId];
builder.ids = ids;
builder.influenceType = DIRECT;
} else {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:@"OSChannelTracker:currentSessionInfluence found a direct influence without a direct id."];
}
}
} else if (_influenceType == INDIRECT) {
if ([self isIndirectSessionEnabled]) {
Expand Down
16 changes: 16 additions & 0 deletions iOS_SDK/OneSignalSDK/UnitTests/ChannelTrackersTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#import "OneSignalHelper.h"

#import "UnitTestCommonMethods.h"
#import "OSNotificationTracker.h"
#import "CommonAsserts.h"

@interface ChannelTrackersTests : XCTestCase
Expand Down Expand Up @@ -167,4 +168,19 @@ - (void)testGetChannelToResetByEntryAction {
XCTAssertEqualObjects(@"iam_id", [[[trackerFactory channelsToResetByEntryAction:NOTIFICATION_CLICK] objectAtIndex:0] idTag]);
}

- (void)testDirectInfluenceWithNullId {
[self setOutcomesParamsEnabled];
OSNotificationTracker *channelTracker = [[OSNotificationTracker alloc] initWithRepository:[OSInfluenceDataRepository sharedInfluenceDataRepository]];
// Set the influence type to direct but do not set the direct id
channelTracker.influenceType = DIRECT;
OSInfluence *influence = [channelTracker currentSessionInfluence];
// The current influence was invalid so the type should be disabled
XCTAssertEqual(influence.influenceType, DISABLED);
// Set the directId
channelTracker.directId = @"testid";
influence = [channelTracker currentSessionInfluence];
// Now that the directId is set the influence should be valid.
XCTAssertEqual(influence.influenceType, DIRECT);
}

@end

0 comments on commit f358fc1

Please sign in to comment.