Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## XX.XX.XX
* Added a new config option disableViewRestartForManualRecording to disable auto close/restart behavior of manual views on app background/foreground actions.

## 25.4.8
* Mitigated an issue where "giveAllConsent" did not include metrics consent.

Expand Down
4 changes: 4 additions & 0 deletions Countly.m
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ - (void)startWithConfig:(CountlyConfig *)config
}
#endif

if(config.disableViewRestartForManualRecording){
CountlyViewTrackingInternal.sharedInstance.isManualViewRestartActive = NO;
}

if(config.experimental.enablePreviousNameRecording) {
CountlyViewTrackingInternal.sharedInstance.enablePreviousNameRecording = YES;
}
Expand Down
5 changes: 5 additions & 0 deletions CountlyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,11 @@ typedef enum : NSUInteger
*/
@property (nonatomic) BOOL disableBackoffMechanism;

/**
* Disable view restarting for manual view recording
*/
@property(nonatomic) BOOL disableViewRestartForManualRecording;

#if (TARGET_OS_IOS)
/**
* Variable to access content configurations.
Expand Down
4 changes: 3 additions & 1 deletion CountlyTests/CountlyBaseTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class CountlyBaseTestCase: XCTestCase {
}

func cleanupState() {
Countly.sharedInstance().halt(true)
// TODO: This also nils the instances which makes testing bad
// Shared instances are static they must not be nilled for multi instance cases.
//Countly.sharedInstance().halt(true)
}
}

Expand Down
48 changes: 34 additions & 14 deletions CountlyTests/CountlyViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,43 @@ class CountlyViewForegroundBackgroundTests: CountlyViewBaseTest {
func testBackgroundAndForegroundTriggers() throws {
let config = createBaseConfig()
Countly.sharedInstance().start(with: config)

Countly.sharedInstance().views().startView("View1")

goBackgroundForeground()

let startedQueuedEventsCount = ["View1": 1]

let endedQueuedEventsDurations = ["View1": [3]]

// Call validateRecordedEvents to check if the events match expectations
validateQueuedViews(startedEventsCount: startedQueuedEventsCount, endedEventsDurations: endedQueuedEventsDurations)

let startedEventsCount = ["View1": 1]

let endedEventsDurations: [String: [Int]] = [:]

// Call validateRecordedEvents to check if the events match expectations
validateRecordedViews(startedEventsCount: startedEventsCount, endedEventsDurations: endedEventsDurations)
}

func testBackgroundAndForegroundTriggers_manualViewRestartDisabled() throws {
let config = createBaseConfig()
config.disableViewRestartForManualRecording = true
Countly.sharedInstance().start(with: config)

Countly.sharedInstance().views().startView("View1")

goBackgroundForeground()

// Call validateRecordedEvents to check if the events match expectations
validateQueuedViews(startedEventsCount: ["View1": 1], endedEventsDurations: [:]) // no end view now

// Call validateRecordedEvents to check if the events match expectations
validateRecordedViews(startedEventsCount: [:], endedEventsDurations: [:])
}

private func goBackgroundForeground() {
// Create expectations for various events
let waitForStart = XCTestExpectation(description: "Wait for 3 seconds before backgrounding app.")
let waitForBackground = XCTestExpectation(description: "Wait for 4 seconds in background.")
Expand All @@ -730,20 +764,6 @@ class CountlyViewForegroundBackgroundTests: CountlyViewBaseTest {

// Wait for all expectations to be fulfilled
wait(for: [waitForStart, waitForBackground, waitForForeground], timeout: 15.0)

let startedQueuedEventsCount = ["View1": 1]

let endedQueuedEventsDurations = ["View1": [3]]

// Call validateRecordedEvents to check if the events match expectations
validateQueuedViews(startedEventsCount: startedQueuedEventsCount, endedEventsDurations: endedQueuedEventsDurations)

let startedEventsCount = ["View1": 1]

let endedEventsDurations: [String: [Int]] = [:]

// Call validateRecordedEvents to check if the events match expectations
validateRecordedViews(startedEventsCount: startedEventsCount, endedEventsDurations: endedEventsDurations)
}
}

Expand Down
2 changes: 2 additions & 0 deletions CountlyViewTrackingInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ extern NSString* const kCountlyVTKeyVisit;
@property (nonatomic) NSString* currentViewName;
@property (nonatomic) NSString* previousViewName;

@property (nonatomic) BOOL isManualViewRestartActive;

+ (instancetype)sharedInstance;

#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
Expand Down
13 changes: 9 additions & 4 deletions CountlyViewTrackingInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ - (instancetype)init
self.viewDataDictionary = NSMutableDictionary.new;
self.viewSegmentation = nil;
self.isFirstView = YES;
self.isManualViewRestartActive = YES;
}

return self;
Expand Down Expand Up @@ -753,23 +754,27 @@ - (NSString*)titleForViewController:(UIViewController *)viewController

- (void)applicationWillEnterForeground {
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
if (!self.isAutoViewTrackingActive) {
if (!self.isAutoViewTrackingActive && self.isManualViewRestartActive) {
[self startStoppedViewsInternal];
}
#else
[self startStoppedViewsInternal];
if (self.isManualViewRestartActive) {
[self startStoppedViewsInternal];
}
#endif
}
- (void)applicationDidEnterBackground {
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
if (self.isAutoViewTrackingActive) {
[self stopCurrentView];
}
else {
else if (self.isManualViewRestartActive) {
[self stopRunningViewsInternal];
}
#else
[self stopRunningViewsInternal];
if (self.isManualViewRestartActive) {
[self stopRunningViewsInternal];
}
#endif
}

Expand Down
Loading